Reputation: 5760
I have create a 'flash' window to show an image during the application start-up. The image is displayed, in my derived QMainWindow constructor I set the flags:
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
My system is an iMAC (Retina 5K, 27-inch, Late 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.
Upvotes: 1
Views: 3685
Reputation: 73081
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)
#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. (I'm testing with Qt 5.12.2 on a 2018 Mac mini running OS/X 10.14.4, FWIW)
Upvotes: 1