How to use Qt Creator to design Graphical Interfaces for PySide
This page describes the use of Qt Creator to create Graphical Interfaces for your PySide Software. You will need Qt Creator, Pyside and PySide-Tools (pyuic and pyrcc).
If you don’t know how to use Qt Creator, please go to Qt Creator Widget Tutorial [doc.qt.digia.com].
At Qt Creator, create a new Qt Design Form, choose “Main Window” for template. And save as “mainwindow.ui” . Add a Qlabel to the center of the centralwidget. You should get somethig like this :

And your mainwindow.ui
- <?xml version="1.0" encoding="UTF-8"?>
- <ui version="4.0">
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>82</width>
- <height>64</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>MainWindow</string>
- </property>
- <widget class="QWidget" name="centralwidget">
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Hello World!</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <widget class="QMenuBar" name="menubar">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>82</width>
- <height>21</height>
- </rect>
- </property>
- </widget>
- <widget class="QStatusBar" name="statusbar"/>
- </widget>
- <resources/>
- <connections/>
- </ui>
Now you run the pyside-uic with this file. The command is:
- pyside-uic mainwindow.ui
The output:
- # -*- coding: utf-8 -*-
- # Form implementation generated from reading ui file 'mainwindow.ui'
- #
- # Created: Mon Dec 10 16:22:24 2012
- # by: pyside-uic 0.2.13 running on PySide 1.1.0
- #
- # WARNING! All changes made in this file will be lost!
- class Ui_MainWindow(object):
- def setupUi(self, MainWindow):
- MainWindow.setObjectName("MainWindow")
- MainWindow.resize(82, 64)
- self.centralwidget.setObjectName("centralwidget")
- self.gridLayout.setObjectName("gridLayout")
- self.label.setObjectName("label")
- self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
- MainWindow.setCentralWidget(self.centralwidget)
- self.menubar.setObjectName("menubar")
- MainWindow.setMenuBar(self.menubar)
- self.statusbar.setObjectName("statusbar")
- MainWindow.setStatusBar(self.statusbar)
- self.retranslateUi(MainWindow)
- def retranslateUi(self, MainWindow):
- MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
- self.label.setText(QtGui.QApplication.translate("MainWindow", "Hello World!", None, QtGui.QApplication.UnicodeUTF8))
With this output you can create a new python module like this:
Save as mainwindow.py.
- # -*- coding: utf-8 -*-
- # Form implementation generated from reading ui file 'mainwindow.ui'
- #
- # Created: Mon Dec 10 16:22:24 2012
- # by: pyside-uic 0.2.13 running on PySide 1.1.0
- #
- # WARNING! All changes made in this file will be lost!
- import sys
- class Ui_MainWindow(object):
- def setupUi(self, MainWindow):
- MainWindow.setObjectName("MainWindow")
- MainWindow.resize(82, 64)
- self.centralwidget.setObjectName("centralwidget")
- self.gridLayout.setObjectName("gridLayout")
- self.label.setObjectName("label")
- self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
- MainWindow.setCentralWidget(self.centralwidget)
- self.menubar.setObjectName("menubar")
- MainWindow.setMenuBar(self.menubar)
- self.statusbar.setObjectName("statusbar")
- MainWindow.setStatusBar(self.statusbar)
- self.retranslateUi(MainWindow)
- def retranslateUi(self, MainWindow):
- MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
- self.label.setText(QtGui.QApplication.translate("MainWindow", "Hello World!", None, QtGui.QApplication.UnicodeUTF8))
- def __init__(self, parent=None):
- super(ControlMainWindow, self).__init__(parent)
- self.ui = Ui_MainWindow()
- self.ui.setupUi(self)
- if __name__ == "__main__":
- mySW = ControlMainWindow()
- mySW.show()
- sys.exit(app.exec_())
And to run:
- python mainwindow.py

