0

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?

frogatto
  • 28,539
  • 11
  • 83
  • 129
Chenna V
  • 10,185
  • 11
  • 77
  • 104

1 Answers1

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.

Ruu
  • 1,245
  • 9
  • 9
  • hmm..If the mainwindow is not the parent of QDialog then the mainwindow would stay minimized anyways and the dialog would appear as a floating window by itself in the middle of the screen irrespective of the mainwindow, which is clearly not a good way of showing application messages to user. For the dialog to appear in an appropriate location we would want the mainwindow as the parent – Chenna V Nov 29 '12 at 18:19
  • Your `QDialog` should be modal dialog. Else, you can't do it. Yet, dirty hack: `hide()` your `QMainWindow` instead minimized. – Ruu Nov 29 '12 at 18:25
  • I created simple program, what it demonstrate that you need (with `hide()` `QMainWindow`). If you want, i can send it. – Ruu Nov 29 '12 at 18:55
  • so u r suggesting to hide() QMainWindow when dialog pops up and setminimized() when dialog closes? – Chenna V Nov 29 '12 at 19:00
  • sure, can you post it on ideone.com or pastebin? – Chenna V Nov 29 '12 at 20:04