3

I'm trying to develop a QGIS plugin. I already created a second window. In that second window, there are several buttons that I need them to work. I can't say I'm a programmer that's why I don't really know what should I add to my main plugin code?

This is the part of the code I included in my main plugin code to show a second window:

def secondscr(self):
    #code the 2nd screen here
    self.Form = QtGui.QWidget()
    self.ui = Ui_Form()
    self.ui.setupUi(self.Form)
    self.Form.show()
    self.Form.comboBox

And then in the run def: I added this line of code

self.dlg.pb_1.clicked.connect(self.secondscr)

Now, I have a comboBox in my second window. I used this code in my run def:

layers = QgsProject.instance().layerTreeRoot().children()
self.dlg.comboBox.clear()
self.dlg.comboBox.addItems([layer.name() for layer in layers])

The problem is that my main plugin code doesn't know what is comboBox (since it only exists in my second window not in my main window).

1
  • Welcome to GIS SE! We're a little different from other sites. We're a Q&A site, not a discussion forum. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an edit button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely. Please check out our short tour for more about how the site works. Thanks.
    – PolyGeo
    May 15 '20 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.