I usually use QGIS Plugin Builder to create working templates for QGIS plugins.

While a generic Python plugin needs the files below;

resources.py (translated from resources.rcc via pyrcc4)
myPlugin_UI.py (translated from myPlugin_UI.ui via pyuic4)

Plugin Builder also creates the following file;


I can understand and use it but why do we need this file myPlugin_dialog.py?

If I import "myPlugin_UI.py" at the beginning, I can already access and interact with the form objects directly from the main module "myPlugin.py"

Why should I need an additional file? What is the advantage of this structure?

(Please explain in basic word since I am not fully fluent with PyQt)

1 Answer 1


Technically the only files you need for a plugin are:


All the other files are just extra stuff depending on what you plugin does. If you don't need any resources (which you normally do) then you don't need resources.rc.

On to your question:


Just hold a class that inherits from your generated ui files. This is just normal Python inheritance and means you can extend the generated code with more logic if needed.

from myPlugin_UI import dialogUI

class MyDialog(dialogUI, QDialog):
   def __init__(self, parent):

   def dosomething(self):

dlg = MyDialog()

You don't need to have this class however if you need to add extra logic to the widget/dialog then this is the preferred method.

  • 1
    Thank you Nathan. I also found a similar explanation that says; "...The whole point of this class is to abstract the the setup of the UI so we don’t have to deal with GUI setup in our main Python module."
    – cempro
    Mar 16, 2014 at 11:20

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.