[英]Qt Window flags set to Qt::WindowStaysOnTopHint but not working
I have create a 'flash' window to show an image during the application start-up.我创建了一个“flash”窗口来在应用程序启动期间显示图像。 The image is displayed, in my derived QMainWindow constructor I set the flags:
图像显示,在我派生的 QMainWindow 构造函数中,我设置了标志:
setWindowFlags(Qt::CustomizeWindowHint
| Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint);
However, when another window is created I am able to drag this new window in-front of the splash window which I don't want.但是,当创建另一个窗口时,我可以将这个新窗口拖到我不想要的初始窗口的前面。 I want the dragged window to be behind the splash window until it is remove.
我希望拖动的窗口在启动窗口后面,直到它被删除。
I search online and what I've set should work but it doesn't.我在网上搜索,我设置的应该有效,但没有。 I'm using Qt Creator 4.9.0 Based on Qt 5.12.2
我正在使用基于 Qt 5.12.2 的 Qt Creator 4.9.0
My system is an iMAC (Retina 5K, 27-inch, Late 2015).我的系统是 iMAC(Retina 5K,27 英寸,2015 年末)。
[Edit] I used the code below to test and prove the fault I'm having, my application window needs to be modal, but I want the splash window to be always on top. [编辑] 我使用下面的代码来测试并证明我遇到的错误,我的应用程序窗口需要是模态的,但我希望启动窗口始终位于顶部。
#include <QMainWindow>
#include <QApplication>
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
QMainWindow * mw = new QMainWindow();
mw->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
mw->resize(500, 500);
mw->show();
QMainWindow * secondWindow = new QMainWindow();
secondWindow->setWindowModality(Qt::ApplicationModal); // <- This breaks the always on top flag
secondWindow->resize(500, 500);
secondWindow->show();
return app.exec();
}
I've tried setting both windows to be modal, that doesn't help either.我试过将两个窗口都设置为模态,这也无济于事。
The following program works for me;以下程序对我有用; does it work for you?
对你起作用吗? (on my Mac, running this program opens an empty gray window that is always in front of all other windows)
(在我的 Mac 上,运行此程序会打开一个空的灰色窗口,该窗口始终位于所有其他窗口的前面)
#include <QMainWindow>
#include <QApplication>
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
QMainWindow * mw = new QMainWindow;
mw->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
mw->resize(500, 500);
mw->show();
QMainWindow * secondWindow = new QMainWindow;
secondWindow->resize(500, 500);
secondWindow->show();
return app.exec();
}
If this program does work for you, then you'll need to figure out how your own program differs from this one;如果这个程序确实适合你,那么你需要弄清楚你自己的程序与这个程序有何不同; OTOH if this program shows the same misbehavior you are seeing in your own program, then it may be there is a bug in the version of Qt that you are using.
OTOH 如果该程序显示出与您在自己的程序中看到的相同的错误行为,则可能是您正在使用的 Qt 版本中存在错误。 (I'm testing with Qt 5.12.2 on a 2018 Mac mini running OS/X 10.14.4, FWIW)
(我正在运行 OS/X 10.14.4,FWIW 的 2018 Mac mini 上使用 Qt 5.12.2 进行测试)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.