PyQt6 create a window with Qt designer and load it

created at 05-09-2021 views: 189

After install and start Qt designer, we can play with it, for example, let's try to create a window with Qt Designer.

Start Qt Designer

reference: install and start Qt designer

Create a blank window

choose Widget and click create:

we will get a empty window:

Set properties of the new window

on the right the yellow table are used to set the display attributes of our window, such as Title, Font, Location of appearance on screen…and so on.

Here we change the windowTitle from default form to PYWD:

Save the window (.ui file)

File--→save, it would be better to create a folder under your project directory to save the ui file. 

and remember to change the default file name untitled.ui to YourName.ui for loading it conveniently.
Mine is:

Loading the ui file (window)

method 1: manually load the ui file

First, we need to create a .py script in the same folder of our .ui file, we name it, and write in:

from PyQt6.QtWidgets import QApplication, QWidget
from PyQt6 import uic
import sys

class UI(QWidget):
    def __init__(self):

        uic.loadUi("Window.ui", self) # load the ui file

app = QApplication(sys.argv)
window = UI()


click run and you will  get a window like:

method 2: use command line to create the loading file

Up to now, our folder looks like this:

switch to the terminal and enter in this folder:

(venv) E:\project\FluidIML>cd PYWD
(venv) E:\project\FluidIML\PYWD>

use this command to create the loading file:

pyuic6 -x Window.ui -o
  • Window.ui: your ui file
  • script to load your ui file

refresh our folder, we will see the script has been created:

what's in it?

# Form implementation generated from reading ui file 'Window.ui'
# Created by: PyQt6 UI code generator 6.0.3
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again.  Do not edit this file unless you know what you are doing.

from PyQt6 import QtCore, QtGui, QtWidgets

class Ui_Form(object):
    def setupUi(self, Form):
        Form.resize(400, 300)


    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "PYWD"))

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_Form()


created at:05-09-2021
edited at: 05-25-2021: