1

For my QGIS Plugin, that I started with the QGIS Plugin Builder, I built a QDockWidget and populated it with some functions.

Now I want to add a QMainWindow, since I need more space for further options, but would like to keep my QDockWidget, in case that one only needs the "simple" Version of the plugin.

I now have build a simple QMainWindow with Qt and want to add it to my plugin. And this is the point where I don't know how to continue.

1
  • You need to explain more your issue, what is your problem? What exactly do you want to do? – etrimaille Mar 18 '20 at 15:09
1

You can use the same mimic as used in your plugin class that inherits from QDockWidget.

If you look into your python code you find something that you can use the same way (provided your QtDesigner file is called my_main_window.ui):

from PyQt5 import uic
MY_FORM_CLASS, _ = uic.loadUiType(os.path.join(os.path.dirname(__file__), 'my_main_window.ui'), resource_suffix='')

class MyMainWindow(QMainWindow, MY_FORM_CLASS):

    def __init__(self, parent=None):
        """Constructor."""
        super(MyMainWindow, self).__init__(parent)
        self.setupUi(self)
        # from here you can use every designer object by self.<objectname>

    def myFunction(self):
        print('Hello!') 

Then you can use this with

my_win = MyMainWindow()
my_win.show()

Sidenote: If you lack some space in your QDockWidget, have you been trying some solutions with QTabWidgets?

1
  • Hey Jochen, thanks for the help, this way it works! And yes already added some Tabs to my QDockWidget ;) – Nunkuat Apr 16 '20 at 13:29

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.