Keep QMainWindow minimized when QDialogs show()

心不动则不痛 提交于 2019-12-25 05:22:43

问题


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:


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.



来源:https://stackoverflow.com/questions/13630980/keep-qmainwindow-minimized-when-qdialogs-show

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!