2

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?

asked Jul 13, 2016 at 11:37
5
  • Is self.d.pushButton_2 (instead of self.dlg.pushButton_2) a typo? This might be the cause of your issue. Commented Jul 13, 2016 at 11:41
  • It's not a typo. There are two dialogs in _init_: # Create the dialog (after translation) and keep reference self.dlg = PluginDialog() self.d = PluginConfigDialog() I'm not sure but if I want to refer to pushButton in second plugindialog I must import it and create a dialog and keep reference to it in _init_ Commented Jul 13, 2016 at 11:45
  • @W.Tom You can also write the listener before the line self.s.show() Commented Jul 13, 2016 at 11:57
  • @eftas Sorry, but I'm not into pyqgis and I don't understand what will it change? Commented Jul 13, 2016 at 12:08
  • stackoverflow.com/a/8763339/4699904 Commented Jul 13, 2016 at 14:56

1 Answer 1

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.

answered Jun 13, 2017 at 12:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.