This might be trivial, but I couldn’t find a solution. So am reaching out.
I am writing a small extension that is supposed to help with labeling some images and segmentation editing in Python. The extension loads the data, and saves its own files on exit. The example at QuickSegment helped me to remove all the unnecessary Slicer details that I do not want. However, when I exit the Slicer window, it pops up the dialog box for confirmation on the scene modifications and hence saving the changes. Is it possible to not pop that dialog up? What would be the corresponding event?
I’m handling the relevant data export on the widget’s exit (i.e. exit()), so I don’t need that dialog to pop up again and confuse my users.
I did some work to override the Slicer drag and drop behavior to do something different that I posted about at
You should be able to use this method for overriding the QMainWindow closeEvent to do your own set of actions instead of the Slicer unsaved changes warning.
Here is some example code that @lassoan then used in the DICOM module to override the regular Slicer drag and drop event behavior.
Note that there is also a solution to override the default save scene behavior (e.g., save/export data automatically, without asking anything from the user), as shown here.
Hi James!
Thanks for the idea! I’ll need to dig into it a little bit deeper, but right now I just modified the behavior of the default dialog box like @lassoan suggested.
I gave complete examples for both customizing the application close behavior (using event filter) and creating a custom save dialog (by adding a new file dialog class). For an optimal user experience probably you want to customize both.
I’ve encountered a side effect of filtering the close event, as there are operations that Slicer performs on close that if we accept the event and return True will not be performed such as saving the window geometry when “Save user interface size and position on exit” option on Settings>Appearance.
If the user saves the scene, there is no problem returning False, because Slicer will close as it detects that the scene is not modified. If the user cancel exiting, it is ok also, because we can reject. But when closing without saving, the user wants to close but the developer needs to allow Slicer to perform its on close events minus opening the close dialog again.
We have recently exposed slicer.util.mainWindow().saveGUIState() method to support this use case. Is there anything else that you would like to do in your custom exit handler?