[Partly Solved] How to detect that a DzDialog is about to Close?
Hi All,
I've been reading this forum for a few years, but this is my first post - so I'll start by saying a big Thank You to all those who have been so generous with their time and knowledge, in particular to:
- mCasual whose site is so useful.
- rbtwhiz
- Richard Haseltine
Now to my question:
I have a DzDialog with a "Close" DzPushbutton that calls a saveDataAndCleanUp() function and then calls the DzDialog.close(). That all works fine:
wDialog = new DzDialog;wCloseButton = new DzPushbutton( wDialog );wCloseButton.text = "Close";connect( wCloseButton, "clicked()", doClose );function doClose(){ saveDataAndCleanUp(); wDialog.close();};function saveDataAndCleanUp(){ // Save changed data, etc...};
But my problem is that if the User closes the dialog by clicking the X button in the dialog's title bar, then my script gets no chance to execute the saveDataAndCleanUp() code.
The wDialog[] array of Members shows a "destroyed()" member, but it does not work for me (maybe because the dialog has closed but not actually been destroyed?):
connect( wDialog, "destroyed()", saveDataAndCleanUp );
In DAZStudio4 SDK/docs/qt/qdialog.html#finished there appears to be the potential for the desired signal, but this does not work either (but does not cause an error):
connect( wDialog, "finished()", saveDataAndCleanUp );
So:
Q1) Is there a way to ensure that saveDataAndCleanUp() gets called no matter how the dialog gets closed?
Q2) If not, then is there a way to disable or hide the X button in the dialog's title bar?
TIA.
Comments
You're welcome.
Take a look at the end of the Simple Input Dialog sample. To cause your function to be called regardless of how it gets closed, don't place it within the conditional, rather place it after your call to
DzDialog::exec()
.DzDialog
::exec()
causes the dialog to be displayed and returns a Boolean value that indicates whether or not the user accepted/rejected the dialog;true
for accept,false
for reject. Clicking the "X" in the title bar of a dialog will cause the return value ofDzDialog::exec()
to befalse
.-Rob
That was quick - thank you Rob.
However...
I'm still very keen to be able to do one or both of these - are they both impossible at present?:
Q1) Is there a way for script to hook into DzDialog finished() or closeEvent()?
Q2) Is there a way for script to disable or hide the X button in the dialog's title bar?
Thanks for any feedback.
In case anyone is interested, this is the best I've come up with so far, and it works OK in my particular application...
This can't detect that a dialog is about to Close, but it does detect that a dialog HAS Closed, because however a DzDialog is Closed, it becomes Hidden. This assumes that there is no other reason for a DzDialog to become Hidden:
Thanks for the question and reply, I was looking at this too (trapping dialog close by clicking in close widget, but Rob had a much better solution, as always.