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