PDA

View Full Version : Drawing a QImage over QWidgets



Antrax
4th October 2006, 17:10
I have a window that has a button. I want to draw a QImage all over the parent, so that it covers the button's graphic. I don't want to inherit and override QPushButton's paintEvent for that, because I need the button to be drawn normally before the parent's paintEvent is called (and the reason I need that is so I get a consistent answer from QPixmap::grabWidget).
So, any ideas how to make the Image be drawn over the children's graphics? Maybe surpress the children's paintEvent somehow?

Trasmeister
4th October 2006, 17:24
If the push button and the image are siblings (IE: both have the same parent), then you can use void QWidget::raise () to move the image widget to the top of the parents child stack.

This should mean that the image widget will now be drawn in frnot of the push button.

Antrax
4th October 2006, 17:56
I'm not sure a QImage can have anything as a parent, it's not a QObject. So, they're not siblings, and playing with raise() and lower() didn't help when I tried it.

Trasmeister
4th October 2006, 18:31
If you are drawing within the parent widget, I don't know of any way to override the way the children paint by allowing the parent to write over them; although it could well be possible.

What you could do, is create a customised QWidget class with an overriden paint method to draw the image and add that into your parent, making it a sibling of the item you want to draw over. This would allow you to raise() the new custom widget to be drawn over the push button (provided you resize it appropriately).

Antrax
5th October 2006, 17:45
Thanks, I'll give it a try in a couple of days.