How to draw something in widget(qt?

QT: Have parent Widget class draw something in addition to the child class widget

  • More and more this seems like a philosophical QT question: I have a widget representing a window A I have a widget representing a window, deriving from A, called B B draws its stuff, but I want "A" to contribute some drawing, e.g. draw an image OVER what "B" draws. I want "B" to be completely unaware of this, not having to cooperate with "A" other than deriving from it. Is that possible?

  • Answer:

    Override http://doc.trolltech.com/latest/qwidget.html#event in A: bool A::event ( QEvent * e) { bool handled = QWidget::event(e); if(e->type() == QEvent::Paint) { // cast e to QPaintEvent and do the overlay painting } return handled; }

RM1970 at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

I'm no QT expert, but you could do this in a hacky way by having A delegate its drawing to a child component of identical size located at (0,0). Naturally, the child component would be drawn after your window widget in the hierarchy, and so this would achieve what you're after.

Nathan Pitman

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.