2

For two QWindow W1 & W2. Is there a way to make W2 always on top of W1? The current method I use is to set W2 always on top by Qt::WindowStaysOnTopHint.

But it also block the modal dialog when the dialog appear behind the window. How can I make sure W2 on top of W1 without blocking the modal dialog?

I use QWindow because W2 is a QQuickView, which is not QWidget.

I am working on windows.

Nyaruko
  • 4,329
  • 9
  • 54
  • 105
  • Is there a reason you can't use QDialog? That would be the intent of QDialog –  Jun 25 '16 at 14:36
  • The QDialog is modal, but it is under the window W2, so I cannot click on that modal QDialog... – Nyaruko Jun 25 '16 at 14:37
  • Why `QWindow`, not `QWidget`? The last allows window flags like `Qt::Window` and `Qt::Tool`. – ilotXXI Jun 25 '16 at 20:05
  • @ilotXXI, I use QWindow because W2 is a QQuickView, which is not QWidget. – Nyaruko Jun 26 '16 at 02:21
  • Typically what you do in Windows programming is arrange for W1 to *own* W2. I don't use Qt, so I don't know how to set up an owned window relationship, but it is very simple with the Win32 API: you just specify the handle to the owner window (in your case, W1) when creating the owned window (W2). The [SDK documentation is here](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632599.aspx#owned_windows). I'll bet Qt allows you to do something similar when creating the window, or perhaps you can set an owner relationship afterwards with something like a `SetOwner` member function. – Cody Gray - on strike Jun 26 '16 at 06:10

2 Answers2

1
w2->setTransientParent(w1);

If you also want to change w2's appearance and behaviour, use QWindow::setFlags.

But it may have side effects. E.g. w2 is closed on w1 close.

ilotXXI
  • 1,075
  • 7
  • 9
0

Try this:

window->setWindowModality(Qt::WindowModal);

You may have to first call this, while the window isn't shown yet, and then call show() on your window, as mentioned here.

Community
  • 1
  • 1
Stefan Monov
  • 11,332
  • 10
  • 63
  • 120