PDA

View Full Version : How to get size of pixmap in qgraphicsitem?



darktorres
23rd July 2014, 02:43
Hi,

I need to paint a red "X" over the image. For that I must get the size of the black rectangle on the screen but I could only get the size of the blue rectangle.
I tried using boundingRect(), viewport(), childrenRect() or similar but none of these worked.

10524

anda_skoa
23rd July 2014, 05:42
How is the image painted?
Is it its own graphics item?
Is it drawn as part of a larger item?

Cheers,
_

darktorres
24th July 2014, 12:42
There is a single QGraphicsPixmapItem in the scene with the pixmap of the head. On top of the view there is a transparent widget where I paint the red X.

Scene[0] -> GraphicsView1 -> Item[0] -> Pixmap (Head)
----------------------------> Overlay (X)

This pixmap is painted with scanLine and the red X with QPainter using the screen coordinates. The problem is that I couldn't get the right coordinates.

anda_skoa
24th July 2014, 13:05
Is the blue area part of the image or the view's background?

Do you need this to be in an overlay window or could you do it in the graphics scene?
Have you considered making the X a part of the image drawing?

Cheers,
_

darktorres
24th July 2014, 15:10
The blue area is the view's background. The problem with painting the X on the scene is that the view can have many items, one on top of the other. But still I need the X to be on top of everything.

anda_skoa
24th July 2014, 18:00
How about QGraphicsScene::drawForeground()?

Cheers,
_

ChrisW67
24th July 2014, 21:42
What did you do with boundingRect() of the pixmap item that did not work? Post a code snippet or two.

darktorres
24th July 2014, 22:12
I tried drawForeground() and it worked great! Thanks!