QGraphicsPixmapItem with Text Label ?

Gunnar Sletta gunnar at trolltech.com
Thu Feb 14 09:15:49 CET 2008


Danny Sporea wrote:
> Is there something like the QGraphicsPixmapItem that
> can be added to a scene and display an image, but also
> with a text label centered underneath ?

Hi Danny,

There is no "direct" API for this, but it is fairly easy to achieve 
using one of the following methods:

  - Create a QGraphicsSimpleTextItem with the text and a 
QGraphicsPixmapItem with the image, both with the same QGraphicsItem 
parent and position under parent relative to each other. Since they 
share the same parent they will transform in unison etc. You may need to 
override the parents boundingbox to get proper behaviour though...

  - Create the <html> text for what you want to achieve and set it as 
the content of a QGraphicsTextItem

  - Subclass QGraphicsItem and do it yourself ;-)

No 2 is probably the most straightforward.

best regards,



More information about the Qt-jambi-interest mailing list