CASE 1: If dialogs are created in the main class
defined in main module of the plugin,
- First, find all attributes of main
class
. (vars(self)
)
- Then, check if any is
QDialog
and is visible. If it is, hide using setVisible(False)
def runCloseDialogs(self):
items = vars(self)
for i in items:
item = items[i]
if isinstance(item, QDialog) and item.isVisible():
item.setVisible(False)
CASE 2: If the plugin has any widget (GUI) which contians other Qt elements (for example QPushButton) and dialog window is opened by that element, in this case, dialog window is (probably) child of main widget (GUI). In this case, self
stands for GUI.
- First, find all
QDialog
s instances of the plugin.
- Then, check if it is visible. If it is, hide using
setVisible(False)
def runCloseDialogs(self):
for dlg in self.findChildren(QDialog):
if dlg.isVisible():
dlg.setVisible(False)
The script above close all dialogs defined in the plugin's GUI.
CASE 3: If you want to close only self.dlg
and self.dlg2
, you can use the following lines:
def runCloseDialogs(self):
if self.dlg.isVisible():
self.dlg.setVisible(False)
if self.dlg2.isVisible():
self.dlg2.setVisible(False)