How to use Qt designer to build desktop applications with Python?

Sowaibaarshad
3 min readJan 24, 2023

--

Qt designer and Python

Qt Designer is a powerful tool for creating user interfaces for desktop applications using Python. It is a part of the Qt framework, which is a collection of libraries and tools for creating cross-platform applications. In this blog post, we will go through the process of creating a simple desktop application using Qt Designer and Python.

Step 1: Install Qt Designer

The first step is to install Qt Designer. You can download the installer from the official Qt website https://build-system.fman.io/qt-designer-download. Once you have downloaded the installer, run it and follow the instructions to install the software. Complete steps for the installation are given here:https://web.stanford.edu/dept/cs_edu/resources/qt/install-windows. You can take help from above mentioned URL for easy installation.

Step 2: Create a new project

Once you have installed Qt Designer, open the software, and a dialog box named “New Form” will appear.

Step 3: Select the form template

In the next step, you will be prompted to select a form template. There are several templates to choose from, including dialogs, main windows, and widget-based forms. For this example, we will use the “Main Window” template.

New Form dialog box in Qt designer

Step 4: Design the user interface

Once you have selected the form template, you can start designing your user interface. Qt Designer has a wide range of widgets that you can use to create your interface. You can add buttons, labels, text boxes, and more. You can also use the “Layout” menu to arrange the widgets on your form.

Step 5: Generate the Python code

Once you have designed your user interface, you need to generate the Python code that will be used to run your application. To do this, go to the “File” menu and select “Save Form as.” Now, the file will be saved as .ui extension.

Step 6: Convert .ui file to .py using command prompt.

To convert a .ui file to a .py file using the command prompt, you can use the command “pyuic5” followed by the path to the .ui file and the path where you want to save the generated .py file.

For example

pyuic5 -x path/to/file.ui -o path/to/output_file.py

This will convert the file.ui file located in the “path/to” directory, and save the generated .py file as “output_file.py” in the “path/to” directory.

Make sure that you have installed the PyQt5 package and you have added the pyuic5.exe to your environment variable.

Step 7: Run the application

The final step is to run your application. To do this, open a terminal or command prompt and navigate to the folder where you saved your Python file. Type “python [your file name].py” and press enter. Your application should now be running.

In conclusion, Qt Designer is a powerful tool for creating user interfaces for desktop applications using Python. It provides a wide range of widgets and layout options, making it easy to design professional-looking interfaces. With a few simple steps, you can create a complete desktop application that can run on multiple platforms.

--

--

Sowaibaarshad

Student, Developer but yet a Learner | C#, Python, Java, SQL