How to toggle WindowCloseButton Hint off and on
-
I am wanting to disable the close window button on a QDialog until a process has finished, I want to disable and enable the button using a boolean as a toggle.
I have written this function but unfortunately I am having no luck. I saw that when I change the window flags it it calls setParent which hides the dialog, but when using show() to reshow the dialog once hidden the application stops responding and I cannot work out what I have done wrong.
void NodeLogDialog::enableButtons(bool bEnabled) { ui->btnOK->setEnabled(bEnabled); ui->btnSave->setEnabled(bEnabled); Qt::WindowFlags flags = this->windowFlags(); if (bEnabled) { setWindowFlags(windowFlags() | (Qt::WindowContextHelpButtonHint) | (Qt::WindowCloseButtonHint)); } else { setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint) & (~Qt::WindowCloseButtonHint)); } show(); }
Thank you in advance
-
Hi,
What version of Qt are you using ?
What OS are you running ?
When/How is that method called in your application ? -
Hey,
I am using QT 5.1.0 and I am running Windows 10 Enterprise.
I create a node dialog object and then call exec from my main window class.
NodeLogDialog oNodeLogDialog(moSuppMgrHubAddress, oSelectedNodes, this); oNodeLogDialog.exec();
The code below is a function within NodeLogDialog.
void NodeLogDialog::enableButtons(bool bEnabled) { ui->btnOK->setEnabled(bEnabled); ui->btnSave->setEnabled(bEnabled); Qt::WindowFlags flags = this->windowFlags(); if (bEnabled) { setWindowFlags(windowFlags() | (Qt::WindowContextHelpButtonHint) | (Qt::WindowCloseButtonHint)); } else { setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint) & (~Qt::WindowCloseButtonHint)); } show(); }
-
@AaronKelsey said in How to toggle WindowCloseButton Hint off and on:
void NodeLogDialog::enableButtons(bool bEnabled)
Where do you call it?
Keep in mind that exec() is a blocking call, so you need to call that method before exec(). -
@AaronKelsey Initially you can call it just before exec().
Afterwards you can use signals/slots to let the dialog know that you want to enable/disable buttons.
But I'm wondering what the trigger is (or who calls it then) after exec() as that one is blocking?