[Qt-interest] making a dialog that shares a taskbar entry but isn't forced on top

Steven Doerfler sgd-qt at lugaru.com
Wed Feb 17 17:18:05 CET 2010


william.crocker at analog.com wrote:
> Steve:
>
> Did you ever get a response to this?
> I was looking forward to more information myself.
>   
No response, but I found a way to make it work acceptably on MS-Windows.

The first trick is to make the dialog a child of a hidden tool window. 
That keeps it off the taskbar without forcing it always on top of the
main window.

    hiddenPreviewParent = new QWidget(0, Qt::Tool);
    previewDlg = new PrintPreviewDialog(printer, hiddenPreviewParent);

But when the user activates the main window, the dialog doesn't rise to
the top.  At first I thought I could fix that by having the main window
call QWidget::stackUnder when it got a QEvent::WindowActivate event. 
But Qt 4.6.1 just ignores the stackUnder.  I could raise() the preview
dialog and then the main window in turn, which gets the two windows to
the top, but this produces an ugly visual flicker.

Instead, I'm using an MS-Windows call

        SetWindowPos(hiddenPreviewParent->winId(), winId(), 0, 0, 0, 0,
                                 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

when the main window gets a WindowActivate.  This works OK, moving both
windows to the top when the user activates   The only drawback is that
the main window always pops up over the preview window when the user
switches to the program, instead of restoring their previous relative
z-order.  (I hope to address that by tracking which window was on top
before the user switched away.)

I think the problem with stackUnder may be a bug.  The stackUnder code
checks whether it's operating on a window, and immediately returns if
so.  Instead, I think it should behave like raise() and lower(): skip
manipulating the parent's list of children when called on a window, but
still call the stackUnder_sys function (which for Windows would perform
a SetWindowPos much like I'm doing explicitly, and would maybe do
appropriate things on other platforms too).

Steven

> Steven Doerfler wrote:
>   
>> I have a main window and a modeless print-preview dialog that the user
>> can hide or show.  The preview dialog should not have its own taskbar
>> entry.  Selecting the taskbar entry should make both windows move on top
>> of other windows.
>>
>> Making the preview dialog a QDialog with the main window as its parent
>> works fine for this, but for one thing: the preview dialog always
>> appears on top of the parent in the z-order.
>>
>> I need to let either the main window or the preview dialog to be on top
>> of the other in the z-order.  I could make them both be main windows by
>> not specifying a parent for the dialog, but then I'd get two taskbar
>> entries.
>>
>> How can I have one taskbar entry (where selecting it brings both windows
>> to the top, without changing their z-ordering), but still allow either
>> window to be on top of the other?  Thanks for any suggestions.
>>
>> Steven
>>
>>     




More information about the Qt-interest-old mailing list