[Partly Solved] How to detect that a DzDialog is about to Close?

PraxisPraxis Posts: 254

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:

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.

Post edited by Praxis on

Comments

  • rbtwhizrbtwhiz Posts: 2,250
    edited April 2016

    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 of DzDialog::exec() to be false.

    -Rob

    Post edited by rbtwhiz on
  • PraxisPraxis Posts: 254

    That was quick - thank you Rob.

  • PraxisPraxis Posts: 254

    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.

  • PraxisPraxis Posts: 254

    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:

    // Initialize:var myDialog = new DzDialog( MainWindow );//  ... etc.: Build myDialog//------------------------------------// Wherever you need to detect if myDialog has Closed, do this:if( myDialogHasClosed() ) {  // ... Do whatever.} else {  // ... Do whatever.}//------------------------------------// A utility to detect if a DzDialog has Closed:var myDialogWasVisible = false;   // Initializefunction myDialogHasClosed()      // : Boolean{  var isClosed = false;  // .visible is a property of the QWidget associated with the DzDialog:  if( myDialog.getWidget().visible ) {    // Signal that the dialog has been Shown since the script started:    myDialogWasVisible = true;  } else {    // The Dialog is not now visible.    if( myDialogWasVisible ) {      // The Dialog was visible, and now is not.      // The Dialog has been Hidden by one of these (are there more ways?):      //  1) myDialog.close() was executed.      //  2) The User clicked the X button in the Dialog's Title bar.      //  3) The User right-clicked the Dialog's Title bar, and chose Close from the popup menu.      //  4) The User pressed Alt+F4, which is the shortcut for 2) above.      //  5) An unhandled exception occured in some part of the Dialog's code.      // The Dialog has been Hidden, so we ASSUME it has Closed:      isClosed = true;    }  }  return isClosed;};  // myDialogHasClosed()

     

  • TotteTotte Posts: 13,965
    edited August 2016

    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. 

     

    Post edited by Totte on
Sign In or Register to comment.