0

I have a QDialog that was created with Qt::WA_DeleteOnClose flag. When specific event happens I need to hide the dialog and restore it later upon another specific event. If I make a call to QWidget::hide() the dialog object is deleted (due to WA_DeleteOnClose) which doesn't work for me.

Unfortunately I can't unset/reset Qt::WA_DeleteOnClose in runtime for certain technical reasons.

The question is: how do I effectively hide QDialog so that it's not visible but still exists? I tried

QDialog* pDlg = ...;
QSizePolicy newSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
pDlg->setSizePolicy(newSizePolicy);
pDlg->setMinimumSize(0,0);
pDlg->resize(0,0); 

but this didn't work. Might it be that I can move the dialog outside the desktop? Or...

I'm solely on Windows if it matters.

Thanks.

ymoreau
  • 3,402
  • 1
  • 22
  • 60
user2724991
  • 121
  • 1
  • 2
  • 6
  • 1
    Can't you temporary remove `Qt::WA_DeleteOnClose` attribute before you hind the dialog and restore it when it becomes visible? – vahancho Apr 01 '14 at 09:19
  • What happens if you use `showMinimized()`? – thuga Apr 01 '14 at 09:24
  • **Try pDlg->hide()** As I said the dialog object is being destructed. **What happens if you use showMinimized()** The dialog gets minimized as if it belongs to the desktop. http://i.imgur.com/TK2mycC.png **temporary remove Qt::WA_DeleteOnClose attribut** Unfortunately I can't. The dialog might be bound to a background thread and when the thread completes it hides the dialog. If I remove the flag the dialog will stay forever and contain outdated data. – user2724991 Apr 01 '14 at 09:55
  • 1
    If you can't temporarily remove the flag, you'll probably have to do it without `Qt::WA_DeleteOnClose` at all and implement some other deletion logic (e.g. delete it manually when your thread finishes) – BBRodriguez Apr 01 '14 at 10:08

0 Answers0