I have made a pushButton - new window relation. Now, when I'm trying to 'link' methods with pushButtons in new window they don't react.
Here is what I wrote in metod, which opens new window in plugin:
def handleButton(self):
self.sc = PluginConfigDialog()
self.sc.show()
result = self.sc.exec_()
I have also added this line in __init__:
self.dlg.pushButton.clicked.connect(self.handleButton)
But when I'm trying to add a alike action with a pushButton_2 in new window, to open another one (third window) nothing happens. Here is code I wrote:
def handleEdit(self):
self.s = PluginEditDialog()
self.s.show()
result = self.s.exec_()
I also added this line to __init__:
self.d.pushButton_2.clicked.connect(self.handleEdit)
I have also added imports for this new windows and create the dialogs (after translation) and keep reference in __init__
Do you know what I'm doing wrong?
1 Answer 1
Here is my approach for solving this:
In your main file import the class which creates the dialog
from style_manager import StyleManagerDialog
connect to a button which opens the new window
# in the init function of the main class self.dlg.mv_pb_styles.clicked.connect(self.t1_load_styles) self.sub_dlg = StyleManagerDialog(self.iface) def t1_load_styles(self): self.sub_dlg.show() res = self.sub_dlg.exec_()
In the class which creates the new dialog import qgis modules and connect to the QGIS iface
from qgis.core import * from qgis.gui import * from qgis.utils import * class StyleManagerDialog(QtGui.QDialog, FORM_CLASS): def __init__(self, iface, parent=None): """Constructor.""" super(VortexStyleManagerDialog, self).__init__(parent) self.iface = iface self.setupUi(self)
in the class which creates the dialog connect to your buttons and write the functions
self.button.clicked.connect(self.style_set_file) def style_set_file(self): filename = QFileDialog.getOpenFileName(self, u"Do Stuff!", "", "QGIS Style (*.qml);;Text (*.txt);;XML(*.xml);; All files(*.*)") # do something with a qgis layer print self.iface.activeLayer().name()
I have tested this approach for QGIS 2.14.15 and it works as from me intended.
self.d.pushButton_2
(instead ofself.dlg.pushButton_2
) a typo? This might be the cause of your issue.