PaintEvent and class topology...
-
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?
-
It is possible, but only with some tricks - it's more a C++ problem than Qt, though.
C++ has the concept of virtual methods, if you reimplement paint() in your subclass B, this method is called, never the method of A. So B has to explicitly call A->paint().
You can declare a virtual method paintPrivate() in class A. Then reimplement paint() in A and call paintPrivate() there. This will call B's paintPrivate(), you then can do your additional stuff in A's paint(). BUT this will only work as long as you do not reimplement paint() in B. If you do everything is lost again.