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?
how to approach a QSpinbox in other widgets?
370 views Asked by Hubschr At
2
There are 2 answers
0
On
You first need to use pyuic to generate a python module from the designer ui file:
pyuic4 -o mainwindow_ui.py mainwindow.ui
Then import it into your application:
from PyQt4 import QtCore, QtGui
from mainwindow_ui import Ui_MainWindow
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setupUi(self)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
This will add all the widgets from Qt Designer, and make them attributes of the MainWindow class. The attribute names will be the same as the objectName property that was set in Qt Designer. So if the QComboBox was named "comboBox", and the QSpinBox named "spinBox", they could be accessed within the MainWindow class like this:
self.comboBox.addItems('Foo')
self.spinBox.setValue(10)
Widgets inside other Widgets do not create hierarchy in Qt, it means that if you have
widget1insidewidget2you can directly access thewidget1, likeself.widget1(andself.widget2)You can create a class which will contain all your widgets on your ui form as follows:
That's all you need.