I'm developing a plugin UI for an existing application using PyQt4. The window is created using uic.loadUi() on the press of a button in the main window. The problem is that if I press the button again (while the window is showing) the window is re-created and unsaved changes are lost. I don't want to make the window modal. Which options do I have to cope with this problem? I guess it would be related to checking whether the QWidget is already showing.
I would have thought that this would be handled more by your application logic than anything else. The main window should disable the button after it has been clicked and then re-enable it again when the window is closed. Connect up a closing signal on the secondary window to a slot on the main window to notify the main window when the secondary window is being closed.
You should initializer a pointer to the QWidget (member variable) to 0.
When the button is pressed, check if the pointer is 0 - if it is, load and show the widget, and assign the pointer variable to point to the new widget. If the pointer is not null when the button is pressed, call widget->raise()
and widget->activateWindow()
.
Disabled buttons can be frustrating to users, as can buttons which appear to do nothing because e.g. their effect is hidden.