Keep QMainWindow minimized when QDialogs show()

2019-09-04 21:24发布

I have an application with QMainWindow as the UI which is in minimized state, after some time the application throws a message by calling messageDlg->show() (messageDlg is a QDialog object). Something like this

void MainWindow::WarningDialog() 
{
    m_messageDialog = new QDialog(this);
    m_messageDialog ->show();
}

This results in my QMainWindow in normal mode which I don't want to happen i.e. am trying to keep the application in minimized window even if any QDialog.show() is called.

I don't want the keep checking if the application in minimized mode every time a QDialog->show() is called.

I've tracked all events posted to QMainWindow::event() but the only event I see happening before restoring my window is a QEvent::WindowStateChange i.e. the window state has already changed from minimized mode.

Is there a way to keep the QMainWindow minimized even if any QDialogs are shown?

1条回答
爷的心禁止访问
2楼-- · 2019-09-04 22:10

QWidget has slot showMinimized(). You should create QDialog without parent as QMainWindow. In your QDialog set attribute (e.g.

 QDialog *dialog = new QDialog;
 dialog->setAttribute(Qt::WA_DeleteOnClose);

), then you can set showMinimized() for QMainWindow in time when your QDialog had start.

查看更多
登录 后发表回答