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
开发者_Python百科 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?
Override 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;
}
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.
精彩评论