View Full Version : QGraphicsScene - tagging picuters

15th September 2009, 21:10

I've got QGraphicsScene, as a background I use a pixmap (I used texture brush). Now I want to make some invisibe rectangular shapes on graphics scene which will be something like tags on the picture. When I move a mouse over a specified field on a picture (where the invisible rectangulars are) I want the rectangular and small cloud with text to appear. Like I wrote before it should work like tags on the picture. I've got some ideas how to do it, but I need your help. The biggest issue for me is a relation of text from the cloud and shape itself.

Thanks for your time

16th September 2009, 09:51
Why not derived your own QGraphicsItem?

Define the shape of your active area by implementing the pure virtual method QGraphicsItem::boundingRect() , then more precisely with QGraphicsItem::shape() .
Then overload mouses event to set a flag member. QGraphicsItem::hoverEnterEvent and QGraphicsItem::hoverLeaveEvent may fit your needs.
Finally, overload the QGraphicsItem::paint method (pure virtual too), to paint your cloud conditionnally to your member flag.

Since the paint do only drawing, item features like selecting, dragging and hovering are still alavailble, even if the paint does nothing.