Ownership of a widget.

Jaroslaw Staniek staniek at kde.org
Sat Feb 9 21:02:16 GMT 2013


On 9 February 2013 21:06, Cyrille Berger Skott <cberger at cberger.net> wrote:
> 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.

+1

Believe me, I had a few such cases in Kexi; usually instantiating from
scratch was a cleaner approach than maintaining code that "resets" the
state of the previous widget instance to _reuse_ it for a new
circumstance. Playing with layouts, manipulating the items is not a
good idea. Remaining doubts can disappear if we think about the
implementation in terms of model/view approach.

For the case Inge is explaining as well as for other cases I imagine
that the view in the side docker shall be completely different (in
terms of layout and number of details) compared to the view attached
to the status bar area. So another point is that usually we have not
much to re-use. It's the most important to keep the overall style and
adhere to the Fitt's law. Ideally, mockup shall be first, no the
implementation. All this makes things harder to deliver.

-- 
regards / pozdrawiam, Jaroslaw Staniek
 Kexi & Calligra & KDE | http://calligra.org/kexi | http://kde.org
 Qt Certified Specialist | http://qt-project.org
 http://www.linkedin.com/in/jstaniek



More information about the calligra-devel mailing list