Search code examples
pyqtqt-designerqspinbox

how to approach a QSpinbox in other widgets?


I'm using Qt-desiger to make a GUI.
For example I have a QSpinbox in a QCombobox in a Groubbox.
How can i use SetValue for my Spinbox? how i have to "describe" the way to my Spinbox?


Solution

  • Widgets inside other Widgets do not create hierarchy in Qt, it means that if you have widget1 inside widget2 you can directly access the widget1, like self.widget1 (and self.widget2)

    You can create a class which will contain all your widgets on your ui form as follows:

    from PyQt4 import uic
    Form, Base = uic.loadUiType(r'path\to\your\uifile.ui') #get ui Form and Base class
    class Window(Form, Base):
        def __init__(self, parent = None):
            #here you can access your widgets
            #self.combobox.addItem('Item')
            #self.spinbox.setValue(10)
            ...
    

    That's all you need.