error panel goes underneath floating window, causing confusion
-
Hi folks. I've got a QWidget-based desktop application that's cross-platform on macOS, Windows, and Linux. There's a glitch that I'm not sure how best to fix: an error panel can open underneath a floating window. When this happens, the app appears to lock up, because the error panel has focus and won't give it up, but at the same time, it is not visible to the user. They can move the floating window aside to reveal the error panel, but that requires that they realize what is happening, and it is very far from obvious – it took a while to figure out what was happening from the user reports!
The floating window is created like so:
QWidget *graphWindow = new QWidget(this, Qt::Window | Qt::Tool); ... graphWindow->show(); graphWindow->raise(); graphWindow->activateWindow();
The "..." is just adding some elements inside the window and such; nothing particularly fancy is going on. I think probably the only important thing here is that Qt::Tool is used as a window attribute, making the window float.
The error panel is created like so:
QMessageBox messageBox(this); messageBox.setText("Simulation Runtime Error"); messageBox.setInformativeText(fullMessage); messageBox.setIcon(QMessageBox::Warning); messageBox.setWindowModality(Qt::WindowModal); messageBox.setFixedWidth(700); // seems to be ignored messageBox.exec();
It seems like either (1) the error panel should float at a higher level than the Qt::Tool window, or (b) Qt::Tool windows should automatically hide when an error panel is up. One way or another, the error panel should always be visible to the user, since it is modal. But at least on macOS, that is not the case, and so the app seems to the user to be locked up, and the user decides they have to force-quit the app.
I imagine that others must have confronted this problem, since both floating Qt::Tool windows and error panels are presumably common. So, has somebody found a good solution for this problem that they can share? Am I doing something wrong in my configuration of the windows that is causing this to occur? Is there a straightforward workaround? Thanks!
-
@bhaller said in error panel goes underneath floating window, causing confusion:
messageBox.setWindowModality(Qt::WindowModal)
Hi, try
Qt::ApplicationModal
here.
Then the dialog box should appear above every other window.
But I'm not sure how theTool
flag behaves in combination with other modal windows. AFAIK the Tool Window only does actual stuff / has an actual effect on MacOS. For the other systems it's like a regular popup. -
Thank you, that change does fix the window level problem! :->
Qt::Tool seems to at least do no harm on other platforms. I mostly develop and test on macOS, so I'd have to check on the other platforms to confirm for sure, but nobody has complained about that. :-> Anyhow, Qt::ApplicationModal solves the immediate problem, thanks!
-