[Qt-interest] why parent widget in constructor?

fluca1978 at infinito.it fluca1978 at infinito.it
Sun Apr 26 14:05:48 CEST 2009


Hi all,
I've got a question about the adoption of a "parent" widget pointer in the
constructors of almost all widgets. I mean, this way when I want to build up
a new widget, say a QPushButton, I have to specify which widget it will be
contained into. Other GUI toolkit, such as Swing, do something different:
GUI blocks are built and then connected together (e.g., using an add method
on the container).
Now, it is clear that the QT approach has one immediate advantage: it allows
a widget to know if it is a top level window widget or not. However I'm
wondering if there's any other tecnhical reason behind this approach. Any
clue?

Moreover, another doubt I've got is this: the parent widget dominates the
display and behaviour of child widgets, meaning that if for instance the
parent widget is not visible, neither the child will be. Now, in the QT
approach the child widget must handle a pointer to its parent, but I guess
that internally something must be set within the parent widget to point to
its child, otherwise how could a child know when it is time to show up or
not? Such information is surely known to the parent widget, but if the
parent widget has no pointer to the child one, how could it know? Again, any
clue or source pointers are welcome.

Thanks,
Luca





More information about the Qt-interest-old mailing list