Painless Introduction to PySide6 and Qt Designer for Beginners

Posted by

PySide6 and Qt Designer Tutorial

A Basic PySide6 and Qt Designer Tutorial

If you’re looking to create graphical user interfaces (GUIs) in Python, PySide6 and Qt Designer are fantastic tools to use. PySide6 is the official set of Python bindings for Qt products, while Qt Designer is a powerful GUI design tool that comes with the Qt framework. In this tutorial, we’ll walk through the basics of creating a simple GUI using PySide6 and Qt Designer.

Step 1: Install PySide6

Before you can start using PySide6, you’ll need to install it. You can do this using pip, the Python package manager, by running the following command in your terminal:

pip install PySide6

Step 2: Install Qt Designer

If you don’t already have Qt Designer installed, you can download it as part of the Qt Creator IDE from the official Qt website. Qt Creator is a cross-platform integrated development environment (IDE) tailored to the needs of Qt developers.

Step 3: Create a Simple GUI

Open Qt Designer and create a new form. You can add various widgets such as buttons, labels, and input fields to design your GUI. Once you’re happy with the layout, save the form as a .ui file.

Step 4: Convert the .ui File to Python Code

Now, you’ll need to convert the .ui file into Python code that can be used with PySide6. You can do this using the pyside6-uic command-line tool. Run the following command in your terminal:

pyside6-uic input.ui -o output.py

Step 5: Use the Generated Python Code in Your Application

Now that you have the Python code generated from your .ui file, you can use it in your PySide6 application. Create a new Python file and import the necessary modules:


from PySide6.QtWidgets import QApplication, QMainWindow
from output import Ui_MainWindow
import sys

Then, create a new class that inherits from both QMainWindow and the Ui_MainWindow class. Inside the class, you can add functionality to your GUI components using the PySide6 API.

Step 6: Run Your Application

Once you’ve finished adding functionality to your GUI, you can run your application by instantiating an instance of the QApplication class and showing your main window.


if __name__ == "__main__":
app = QApplication(sys.argv)
mainWindow = MyMainWindow()
mainWindow.show()
sys.exit(app.exec_())

And there you have it! You’ve successfully created a simple GUI using PySide6 and Qt Designer. This is just the tip of the iceberg when it comes to what you can achieve with these tools, so feel free to explore further and create more complex and feature-rich applications.

0 0 votes
Article Rating
27 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@cornevanzyl5880
6 months ago

If you execute another eventloop how do you pass information from one window to another?

@EmmanuelRojasAngeles-tg7ss
6 months ago

HOw come your QT designer has QT Icons on in its tool bar and if so How can I add those Myself? If you dont mind explaining please

@eteichma
6 months ago

BEST.TUTORIAL.EVER!
I started getting into Python a month ago. Before that a handcore Java programmer. A very frustrating journey, as I only found snippets of disconnected information on the web and youtube, regarding Python GUI development. I could not find a structured tutorial that gives a clear overview of the various development environments, the libraries and how it all fits together. Until this one. Great job! Thank you for your contribution.
👍

@shirochan4769
6 months ago

If i use pyside6 with qtcreator, does it still LGPL or GPL?

@UsfCodes
6 months ago

can you give me the external tool scrip,ik what to write in the argument and the working dir but not in the program

@brianjones5193
6 months ago

Excellent video, although I've coded a couple of small PyQT apps I have learned a lot from this. Love the idea of QT tools for uic etc and have copied that. Love the idea of the iqi shortcut (and I'd do one for the Main with Application loop too amongst other things) but not sure where to set this up in Pycharm – I assume it's a macro?

@eto895
6 months ago

thanks .. appreciate it. Need more tutorial to design modern gui.

@SneakoV2
6 months ago

is there a difference in features between QT Creator and Designer?

@digiital
6 months ago

GREAT Tutorial.. Sometimes I need one of those Lightbulb videos to fully understand a new python tool and this did it. I have been so far this week been converting my alittle scripts/apps that used SimpleGUI . Pyside6 is sooooooooooooooo easy so far to understand.

Request!

One thing I am struggling with is more complex front ends. How about a video on front end where you have several labels/inputs/buttons

@visasimbu
6 months ago

I am confused on selecting pyQt6 or Pyside6. I am new and search engine gives me diff on license. I plan to release my s/w as open source without sharing code. which one suffice ?

@abolfazlshahi2916
6 months ago

It was one the best tutorials I've seen in my life thank u so much for this course 🤍

@ionarn1532
6 months ago

Hiho, this is the best Qt related tutorial for Python I've seen so far – Thank you!

I have a question though:

You've put your Icons_rc,py in the folder "Sample_Application". I tried the same, but then python spits out the error: "ModuleNotFoundError: No module named 'Icons_rc'".

When I put the "Icons_rc,py" in the same folder as the logic file, for example "add_person,py", then it works. But that means I have to duplicate the "Icons_rc,py" files each time I want to create anything new with the Qt Designer.

I guess with a larger project and bigger and more Icons this would quickly become very bloated and difficult to manage.

Do you have an idea of what I have to change to make it work as shown in your tutorial?
btw: I replaced the "." in the file naming with a "," – otherwise YouTube would immediately delete my comment.

@pdep
6 months ago

Brilliant. Much appreciated. I would like to see a full [complex] application course on this and would be quite prepared to pay for it. There are no doubt many others of the same mind, so please consider it. Thank you. 👍

@carstenjensen3123
6 months ago

Amazingly good tutorial. Great project to show the use of QT, very clear explanations and reasoning and a really good tempo. You can easily break it up in smaller chunks and still follow along. Great!

@TimLauridsen
6 months ago

great tutorial

@marsma18
6 months ago

I still have a issue with bigger app and one main window which would cose main class huge. For example pycharm window UI. Is it possible to extract every menu to other class and other things on screen to other class and then embed everything in one supervisor class with just functionality of show and hide different thing and keep them organised.

BTW. Super usefull video with excellent explanation. Thanks!

@robertmcdonnell2807
6 months ago

Thank you so much. Exactly what I needed to know, workflow and connecting things up

@pailsOfGrease
6 months ago

⭐⭐⭐⭐⭐ Outstanding tutorial!

@TheAmazingpower
6 months ago

This was quite a good and informative video. It covered a good ground of basic to intermediate things, thanks for that. Even though I did use PyQt in my Open Source Project (CocktailBerry) for some years now, there are a few things which I might use now because did not know them up till now!

@joeking5211
6 months ago

About the 5th or more times thought with your video ( and a few of your others ), that I first spotted about 2 weeks back when I thought that Qt was worth a look. Only thing was I could'nt write a line of python code let alone use or know anything about Qt, and Pycharm was a jumble. Just to say that due to this vid I now have Pycharm running ( almost like yours with all the External tool menus you have including PyInstaller ), and now have an application I wrote in another language a few years ago now cloned as 'proof of concept' to perfection using Pyside6, I want to thank you so much for your smooth precise pace of your videos. My only issues now as you will understand as with any language/IDE in getting to know/understand and decipher the Qt library docs, that is now the biggest issue, but time and practice is the only cure for that. Thank you so much again for your time and patience which without I would'nt have done this, Qdos to you sir, will keep an eye on you video list.