QDialog doesn't stay on top....
-
Hi,
i have a problem where i show a modeless dialog in which the User has the ability to pick a color from a control within the main window.
On PC1(My development PC) it works as expected. On PC2 it behaves much different. When i click anywhere outside the dialog, it gets hidden behind the MainWindow. In the documentation it says ". A dialog is always a top-level widget...", that doesn't seem to be the case.
I already tried to set the WindowStaysOnTopHint inside the Dialog constructor, but it doesn't change anything.This is how i initialize the Dialog:
m_recordDialog = new RecordDialog(this);
And this is how i present it:
m_recordDialog->show();
I'm using Qt 5.12.2(x64) and Visual Studio 2015.
Dosfried
-
@Dosfried said in QDialog doesn't stay on top....:
m_recordDialog->show();
you can use exec() instead of show() if you want your dialog to block everything else, then it will be always on top.
Else you can set Qt::WindowStaysOnTopHint via https://doc.qt.io/qt-5/qwidget.html#setAttribute
-
@jsulm
The trouble is the OP states:I already tried to set the WindowStaysOnTopHint inside the Dialog constructor, but it doesn't change anything.
And he wants modeless, so not
exec()
.@Dosfried
I am interested in whether you really do find this behaviour. I am currently having to work on modeless/stay on top, but I only have access to Linux where it does behave differently from Windows which I also have to support! It should not just be different across different PCs AFAIK. Are they running the same Windows version? Is there some other difference? -
First of all thanks for the fast reply's. I really appreciate it.
@jsulm
I cannot use exec, because my dialog needs to be modeless. Otherwise i cannot use the color picker functionality from my RecordDialog class.
I already tried setting this flag. It doesn't make any difference...@JonB
What do you mean by "I am interested in whether you really do find this behaviour."
I am definitely getting this behavior on different machines here at work.On my desktop pc everything works as expected. On my co workers laptop everything works as expected.
But on the Laptop where the software should finally run, it is acting strange...Every computer which i tried runs Windows 10 (Either Home or Enterprise)
-
What do you mean by "I am interested in whether you really do find this behaviour."
Every computer which i tried runs Windows 10 (Either Home or Enterprise)I meant that, especially since you say they are now all running the same Windows, I really don't think you should be finding they exhibit different behaviour. Either they should all have it on top, or none of them should have it on top, but you should not be seeing some with one behaviour and some with the other. Ultimately I would expect the Qt code to set some native Windows flag for the behaviour, and that should behave consistently.
What about creating an absolutely minimal example for your code/behaviour and then posting it here if you find different behaviour so that others can test?
-
Okay i think i narrowed it down quite a bit.
I am only experiencing this behaviour when i am using a QOpenGLWidget inside my MainWindowand the Computer only has an integrated graphics card....Here is a minimal example.
// main.cpp #include "MainWindow.h" #include <QApplication> int main(int argc, char* argv[]) { QApplication application(argc, argv); MainWindow window; window.showFullScreen(); return application.exec(); }
//MainWindow.h #pragma once #include <QMainWindow> #include "ui_MainWindow.h" class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget* parent = nullptr); private slots: void onAction(); private: Ui::MainWindow m_form; QOpenGLWidget* m_glWidget; QDialog* m_dialog; };
//MainWindow.cpp #include "MainWindow.h" #include <QAction> #include <QDialog> #include <QOpenGLWidget> MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { m_form.setupUi(this); m_glWidget = new QOpenGLWidget(this); setCentralWidget(m_glWidget); QAction* dialogAction = new QAction("Open Dialog", this); connect(dialogAction, &QAction::triggered, this, &MainWindow::onAction); m_form.toolBar->addAction(dialogAction); m_dialog = new QDialog(this); } void MainWindow::onAction() { m_dialog->show(); }
Can anybody confim this?