Ownership of a widget.

Cyrille Berger Skott cberger at cberger.net
Sat Feb 9 20:06:10 GMT 2013


On Saturday 09 Feb 2013, Inge Wallin, Lysator wrote:
> But who should own the widget? Can the docker continue to own the widget
> even  though it physically resides inside the statusbar? somebody must
> control the widget when it moves from one location to the other and I
> don't think it's obvious who that somebody is.

Nope. A QWidget is owned by its parent, and when you have a widget that need 
to be shown inside an other widget, then it has to be owned by that widget. 
From Qt's documentation:

"Top-Level and Child Widgets
A widget without a parent widget is always an independent window (top-level 
widget). For these widgets, setWindowTitle() and setWindowIcon() set the title 
bar and icon respectively.
Non-window widgets are child widgets, displayed within their parent widgets. 
Most widgets in Qt are mainly useful as child widgets. For example, it is 
possible to display a button as a top-level window, but most people prefer to 
put their buttons inside other widgets, such as QDialog.
"

> Does anybody have an idea?  I can give more details but my train leaves now
> so  I need to go now.
Euh yea, have two instance of your widget, one for the docker and one for the 
status bar. Having a widget that "jumps" between parents is a call for 
breakage, maintenance nightmare, bugs and crashes.

-- 
Cyrille Berger Skott



More information about the calligra-devel mailing list