1

Is it possible to run separate python processes through tab widgets of the same QGIS plugin. I have created a QGIS plugin using the plugin builder. From QT designer I added two tab widgets to the plugin. I want to run different processes in both the tabs, one at a time though. Right now I can run the process in the first Tab, but I do not know how to add the script to the second tab and run it when the 'OK' button in second tab is clicked.

0

Just define separate class methods in your main plugin class and connect them to different buttons in your UI tabs. For example, if you have buttons with object names like ok_btn_1 and ok_btn_2, in the initGui method of your main plugin file, connect the clicked signal to the methods which contain the 'processes' you want to run.

def initGui(self):
    ...
    self.dlg.ok_btn_1.clicked.connect(self.process_1)
    self.dlg.ok_btn_2.clicked.connect(self.process_2)

then make sure you have defined those class methods:

def process_1(self):
    # Do something

def process_2(self):
    # Do something else

I have just created a GitHub repository with an example of a simple plugin with a tabbed UI (created without PluginBuilder or QtDesigner). Hopefully you may find it useful:

https://github.com/benwirf/QGIS_Example_Plugins/tree/master/test_plugin

  • Thanks, I understood up till here and even managed to have tow tab widgets in the plugin (I used the QGIS plugin builder). In the second widget I added a push button and could run the process, but how to add one button to close the plugin interface, like the default 'QDialogButtonBox' that comes from QGIS plugin builder? – Dew_ale Nov 23 '19 at 16:31
  • No worries @Dew_ale. The method to close the whole dialog will be self.dlg.close(). Now that you understand a little about event handling, you should be able to work out how to add a button to your main dialog, (not in the tab widgets) and connect it to a function which implements that method. Hint: for a one line function, it often makes sense to pass a lambda function e.g. something like self.dlg.btn_close.clicked.connect(lambda: self.dlg.close()). – Ben W Nov 25 '19 at 8:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.