Discussion:
[Interest] Find frontmost widget of specific type?
Israel Brewster
2018-10-22 18:37:56 UTC
Permalink
I have an application (Qt 5.9) that has a variety of different types of windows you can open. If a user selects to open a type of window that is already open, I want to position the new window relative to the existing one. I can easily find any existing windows of a given type by going through the list of widgets in QApplication::allWidgets(), doing a qobject_cast to the proper type, and checking the result, but is there a way to determine which of these is the frontmost of that type? QApplication::ActiveWindow() doesn't help, because the activeWindow may not be of that type.

-----------------------------------------------
Israel Brewster
Systems Analyst II
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
-----------------------------------------------

[cid:6da0fc9b-4232-4d70-8cd7-***@flyravn.com]



[cid:fd4128fd-46d2-40d0-a243-***@flyravn.com]
John Weeks
2018-10-22 20:37:36 UTC
Permalink
We faced pretty much exactly this issue when we ported our very large application to Qt, starting with Qt 4.8. We have many places where we expect to be able to walk a window list in Z order. I wound up using Activate/Deactivate events to keep the list myself. I can't really recommend it- it has been pretty much of a nightmare to make it robust and bug-free, especially as Qt has a couple of bugs in their own notion of window activation. You can't really use the debugger to debug these issues, as the activation of the debugger changes the activation of the application's windows.

I have made it work pretty well, but I quake in my boots whenever I get a bug report about window order.

We are now using Qt 5.9 and don't have any sort of replacement for my delicate and difficult code.

-John Weeks
WaveMetrics, Inc.
I have an application (Qt 5.9) that has a variety of different types of windows you can open. If a user selects to open a type of window that is already open, I want to position the new window relative to the existing one. I can easily find any existing windows of a given type by going through the list of widgets in QApplication::allWidgets(), doing a qobject_cast to the proper type, and checking the result, but is there a way to determine which of these is the frontmost of that type? QApplication::ActiveWindow() doesn't help, because the activeWindow may not be of that type.
-----------------------------------------------
Israel Brewster
Systems Analyst II
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
-----------------------------------------------
<image001.jpg>
<image002.jpg>
<Israel Brewster.vcf>_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Henry Skoglund
2018-10-22 21:22:24 UTC
Permalink
Post by John Weeks
We faced pretty much exactly this issue when we ported our very large application to Qt, starting with Qt 4.8. We have many places where we expect to be able to walk a window list in Z order. I wound up using Activate/Deactivate events to keep the list myself. I can't really recommend it- it has been pretty much of a nightmare to make it robust and bug-free, especially as Qt has a couple of bugs in their own notion of window activation. You can't really use the debugger to debug these issues, as the activation of the debugger changes the activation of the application's windows.
I have made it work pretty well, but I quake in my boots whenever I get a bug report about window order.
We are now using Qt 5.9 and don't have any sort of replacement for my delicate and difficult code.
-John Weeks
WaveMetrics, Inc.
I have an application (Qt 5.9) that has a variety of different types of windows you can open. If a user selects to open a type of window that is already open, I want to position the new window relative to the existing one. I can easily find any existing windows of a given type by going through the list of widgets in QApplication::allWidgets(), doing a qobject_cast to the proper type, and checking the result, but is there a way to determine which of these is the frontmost of that type? QApplication::ActiveWindow() doesn't help, because the activeWindow may not be of that type.
....
Hi, just an idea, but obviously somewhere deep inside Qt's bowels
(rather, the painting system) there's knowledge of which window obscures
which etc.

Say you issue a dummy QWidget::update() on your topmost/app window, then
catches all the QPaintEvents that are called. Inside those QPaintEvents
is a QPaintEvent::rect() that holds the rectangle that needs to be
updated/repainted. If you then search your QApplication::allWidgets()'s
list of rectangles; then I think (guessing) that only the
topmost/foremost windows will match QPaintEvent's rectangles. I.e.
windows that are partially or fully obscured by another window should
receive a smaller (or none) rectangle in those QPaintEvents. That could
be one way to establish a z-order on the fly...

Rgrds Henry
Henry Skoglund
2018-10-22 21:42:33 UTC
Permalink
Post by Henry Skoglund
Hi, just an idea, but obviously somewhere deep inside Qt's bowels
(rather, the painting system) there's knowledge of which window obscures
which etc.
There isn't. Compositing window managers have been a reality on desktop
machines since Mac OS X 10.2 (2002), maybe even before that.
The only really robust approach is asking the WM what are the visible
windows and their stacking order. Keeping the order in Qt is also
feasable, modulo of course bugs in the Qt / WM interaction...
My 2 c,
Ok, I see, nice try but 16 years too late. I guess that only shows my
age :-(

Rgds Henry

Loading...