K
K
kristian3072019-09-25 11:50:11
Qt
kristian307, 2019-09-25 11:50:11

How to make a QGraphicsItem that can be both an image and text?

Hello. Faced such a problem. I want to make a graphic element, which can be either a picture or text. That is, this element has the setting "Display as an image" and I want either an image or text to be displayed depending on this.
Now my count. the element is inherited from QGraphicsPixmapItem, but I never found a way to make it so that I can write text to it.
How can I combine the ability to display both text and an image? Shouldn't it inherit from QGraphicsPixmapItem and QGraphicsTextItem?
Or maybe I need to inherit my QGraphicsItem, in which I will have to implement all this? Then tell me, please, an approximate procedure, because I could not find anything similar in Google.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2019-09-25
@myjcom

QLabel can "be" either a picture or text
https://forum.qt.io/topic/82420/show-picture-using...

I
Ivan Klimenko, 2019-09-25
@yeswell

Shouldn't it inherit from QGraphicsPixmapItem and QGraphicsTextItem?
- why not? You clearly have two different tasks that must be performed, however, by one class. But inside they will still remain different.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question