添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode . Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

Hi All,
I examined Qt::WindowStaysOnTopHint flag of widget via Examples\Qt-5.9.1\widgets\widgets\windowflags application.
The window with such a flag stays always foreground even I click to the other, not mine, application.
It looks very strange. I need the window to be always shown on the screen but only inside my application. Not on the top of web-browser, Skype, mail and all-all-all applications on my computer!
Is there any way provided to achieve that?
Thank you!

That is what WindowStaysOnTopHint does when the OS supports it.
You can use QDialog to open a window that will stay on top of mainwindow.
At least when its modal.

But what effect are you after ?

There are also http://doc.qt.io/qt-5/qdockwidget.html
which allowed to be embedded into main app but also floated and become a windows on its on.
Sort of like an old MDI app but with free windows.

Thanks for your answer.
My application is an editor fundamentally (I mean UI) like Adobe Photoshop for example. It has working windows and auxiliary toolbars and panels.
I want toolbars and panels be always foreground for working windows.

It's so cool on Mac: Qt::Tool windows have foreground priority on Qt::Window windows.
"On macOS, tool windows correspond to the Floating class of windows. This means that the window lives on a level above normal windows making it impossible to put a normal window on top of it. "
I want to have the same on Windows!
Qt::WindowStaysOnTopHint seems to do what I need, but my panels are ALWAYS stay on the screen for all applications. Who needs that?

Now I try to set and clean WindowStaysOnTopHint on QEvent::ApplicationActivate and QEvent::ApplicationDeactivate but I have a lot of weird side effects.! 0_1510642908415_panels.png

Actually official qt's example \Qt5.9.1\Examples\Qt-5.9.1\widgets\widgets\windowflags is enough.
I'll try qt 5.9.2 now, but for 5.9.1 Qt::Window and Qt::WindowStaysOnTopHint chosen in "windowflags" example application make resulting window to stay on the screen in spite of current active program.

Qt support has helped me. Windows with WindowStaysOnTopHint really should always stay foreground on the screen. It's proper behaviour. So the following code made my goal:

connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(doStaysOnTopFlagProcessing(Qt::ApplicationState)));

void MyToolbar::doStaysOnTopFlagProcessing(Qt::ApplicationState s)
//if (parentWidget()) return;
if (s == Qt::ApplicationActive) {
setWindowFlag(Qt::WindowStaysOnTopHint);
show();
else {
setWindowFlag(Qt::WindowStaysOnTopHint, false);
lower(); // or hide()