Qt Designer helps you build a GUI (graphical user interface). You can load a GUI from Python. In this tutorial we’ll show you step by step.

It covers a very basic example of how to use Qt Designer with PyQt and Python. For more details see the link below.

Related Course: Create GUI Apps with Python PyQt5

Qt Designer Python

Prerequisites

To start with this tutorial you need these installed:

  • Python
  • PyQt
  • Qt Designer

You will need Python 3 or above, because the others are out dated.

If you don’t have PyQt, install PyQt.

You can install Designer (Ubuntu Linux) with:

1
2
sudo apt-get install qttools5-dev-tools
sudo apt-get install qttools5-dev

On other platforms it’s included in the setup.

How to start Designer

Start designer by typing designer in the command line. Important: qt creator is another program.

On Ubuntu Linux:

1
2
cd /usr/lib/x86_64-linux-gnu/qt5/bin/ 
./designer

Basics

A popup shows up. You can choose what you want to design.

pyqt designer

Choose “Main Window” and click create.

You can then resize the form and drag and drop widgets. It’s pretty simple to design a graphical interface like this.

If you click on a widget (say a button), you can set its properties like name.

qt designer

If you are new to Python PyQt, then I highly recommend this book.

Export Design to UI

You can export your design to a UI file. Click File > Save As > yourname.ui

Then you can convert the ui code to a python file.
Like this:

1
pyuic5 /home/linux/helloworld.ui -o helloworld.py

The Python file then contains the gui definition.
Create another file that loads the ui file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication
import sys
import helloworld

class ExampleApp(QtWidgets.QMainWindow, helloworld.Ui_MainWindow):
def __init__(self, parent=None):
super(ExampleApp, self).__init__(parent)
self.setupUi(self)

def main():
app = QApplication(sys.argv)
form = ExampleApp()
form.show()
app.exec_()

if __name__ == '__main__':
main()

Once you run it your GUI appears.

Download Examples