0

My development environment is Red hat 8.
Minimal reproducible example :

#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QDialog>
int main(int argc, char *argv[]) {
 QApplication app(argc, argv);
 QMainWindow mainWin;
 QPushButton btn("Show Dialog", &mainWin);
 mainWin.setCentralWidget(&btn);
 QObject::connect(&btn, &QPushButton::clicked, [&](){
 QDialog *dialog = new QDialog(this);
 dialog->exec();
 });
 mainWin.show();
 return app.exec();
}

As a result, when the Dialog UI is opened and then the Linux workspace is switched, the Dialog also moves to the new workspace, after closing the Dialog, the MainWindow UI may exhibit unexpected behavior. I have tried many solutions but none have worked.
I accidently discovered that Dialogs are displayed in the menu bar don't switched with workspace. So, I change the code:

QDialog *dialog = new QDialog(nullptr);// Some Dialogs are ok, but some problems still exist

Then, I change the code, the problem was solved:

#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QDialog>
int main(int argc, char *argv[]) {
 QApplication app(argc, argv);
 QMainWindow mainWin;
 QPushButton btn("Show Dialog", &mainWin);
 mainWin.setCentralWidget(&btn);
 QObject::connect(&btn, &QPushButton::clicked, [&](){
 QDialog *dialog = new QDialog(nullptr);
 dialog->setWindowFlags(Qt::Window);
 dialog->exec();
 });
 mainWin.show();
 return app.exec();
}

I want to know the reason, thanks~~

Additional information:

1.The Dialogs are constructed by *.ui method will not switched when workspace changed.

2.QT version:5.9.3 ; Desktop env: Mate; Windows manger: Marco

DarkBee
14.4k9 gold badges86 silver badges135 bronze badges
asked Nov 19, 2025 at 3:15

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.