[Qt-interest] Window list in z-order?

Malyushytsky, Alex alex at wai.com
Wed Feb 9 03:00:49 CET 2011


If I understand your goal,
I would  probably maintain “top window containing document of specific kind” myself.
Just when certain widget gets focus it replaces previous top.
It sounds better to me even if you really need to keep a full z-order list for every type of widget.

This would allow me not to rely on Qt coding which was probably created for different purpose.
I can’t say if QApplication:: allWidgets()  maintains Z-order or not.

Documentation seems not full of details on z-order, but in QWidget topic it is mentioned that:

“The widget is the atom of the user interface: it receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen. Every widget is rectangular, and they are sorted in a Z-order.“

I would say z-order in that context is more confusing than helpful.
It is not clear how and where this order is maintained.
So personally I would not rely on such information.

But I can give my guesses.
Even though they are based on some experience and Qt documentation,
I would not recommend build your solution on them at least without testing:

 - Every widget maintains the list of its (widget) children sorted in Z-order.
 - You can get such list using:
          const QObjectList & QObject::children () const
 - The first child added is the first object in the list and the last child added is the last object in the list, i.e. new children are appended at the end.
 - Searching in above QObjectList or using
   T QObject::findChild ( const QString & name = QString() ) const,
   QList<T>     findChildren ( const QString & name = QString() ) const
   You might be able to get childs of your main window in specific order.

Regards,
  Alex


From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of John Weeks
Sent: Tuesday, February 08, 2011 12:47 PM
To: Qt-interest Interest
Subject: [Qt-interest] Window list in z-order?

Hi, all- I posted this a while back (Oct. 6, 2010, to be exact) so I think there's been time for everyone to have seen it :) I've hit a need for a solution to this, and still haven't found the answer. I'm hoping someone might have some insight. Thanks!



Our application has document windows of many kinds (think along the lines of a scientific IDE). A common action is to find the top document of a given kind. Presently, in Macintosh and Windows code, we get the top (in z-order) window of any kind, then walk down the window list looking for the first one of the given kind.

Can anyone suggest a way to implement this in Qt? These document "windows" might be actual windows (QMainWindow or just QWidget with custom code to make it functioning window), or they might be QMdiSubWindow (which isn't an actual window).

I see QApplication::topLevelWidgets() and QApplication::allWidgets(). The documentation doesn't tell me about the ordering of the list. It also seems like allWidgets would probably include too many widgets, and topLevelWidgets would include only widgets that are also windows. Am I right about that?

I also see QApplication::focusWidget(). That seems like it might give me something like the top window in z-order, but it might also give me a sub-widget of a compound widget.

Will I have to roll my own document-in-Z-order list and maintain it myself?

Regards,
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax   (503) 620-6754
email   support at WaveMetrics.com



---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”


More information about the Qt-interest-old mailing list