How to disable all options of QDialog closure
-
Hi
Docs says
In order to modify your dialog's close behavior, you can reimplement the functions accept(), reject() or done(). The "closeEvent() function should only be reimplemented to preserve the dialog's position or to override the standard close or reject behavior."So i think you should override accept(), reject() and handle it that way.
-
Hello!
Additionally, you can try to make the dialog without controls by setting the code below:
setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
The user can not minimize/maximize or close such dialog:
Also, you can modify the
nativeEvent
to intercept the dialog closure: https://forum.qt.io/topic/104533/how-to-ignore-the-event-when-i-click-on-the-button-to-maximize-the-window-windowmaximizebuttonhint/9Happy coding!
-
@Cobra91151 said in How to disable all options of QDialog closure:
The user can not minimize/maximize or close such dialog:
I cannot test this, but OOI what does pressing Alt+F4 under Windows on this dialog do?
-
@Cobra91151 said in How to disable all options of QDialog closure:
and overriding the native event
Indeed! My question was whether this was required to make it work robustly; if you only do the
setWindowFlags()
I wondered whether the keyboard shortcut would still cause closure? -
Even when
setWindowFlags
are set, you have to intercept the dialog closure using thenativeEvent
.Code:
bool TestDlg::nativeEvent(const QByteArray &eventType, void *message, long *) { qDebug() << eventType; MSG *msg = static_cast<MSG *>(message); #ifdef __linux__ //Linux code here #elif _WIN32 if (msg->message == WM_SYSCOMMAND) { if (msg->wParam == SC_CLOSE) { QMessageBox::information(this, "Test", "Closing...", QMessageBox::Ok); //Add your code here return true; } } #endif return false; }
-
@Cobra91151
Which is what I suspected, hence the question.Your original answer made the
nativeEvent
interception look "optional" ("you can modify"), now the OP knows it is mandatory.