From 8a86f8a2533cb66480a165cffbbf24e800e03123 Mon Sep 17 00:00:00 2001 From: realpython-bot Date: Mon, 29 Jun 2026 11:28:48 +0000 Subject: [PATCH 1/5] Update Qt Designer sample editor to PyQt6 Migrate the qt-designer-python sample text editor from PyQt5 to PyQt6 to match the refreshed tutorial: - Regenerate main_window_ui.py with pyuic6 (PyQt6 6.11.0) - Update app.py imports to PyQt6 (QtWidgets and uic) - Update README install instructions to PyQt6 Verified: the app builds its GUI (setupUi) and loads find_replace.ui via uic.loadUi() under PyQt6 on Python 3.14. Co-Authored-By: Claude Opus 4.8 (1M context) --- qt-designer-python/README.md | 6 +- qt-designer-python/sample_editor/app.py | 4 +- .../sample_editor/main_window_ui.py | 136 ++++++------------ 3 files changed, 46 insertions(+), 100 deletions(-) diff --git a/qt-designer-python/README.md b/qt-designer-python/README.md index 3aa3bdbae4..9e890d16ff 100644 --- a/qt-designer-python/README.md +++ b/qt-designer-python/README.md @@ -4,15 +4,15 @@ A **sample text editor** that shows how to use Qt Designer to create GUI applica ## How to Run this Application -To run this application, you need to [install `PyQt5`](https://realpython.com/python-pyqt-gui-calculator/#installing-pyqt) on your Python environment. To do that, you can run the following commands in a terminal or command prompt: +To run this application, you need to [install `PyQt6`](https://realpython.com/python-pyqt-gui-calculator/#installing-pyqt) on your Python environment. To do that, you can run the following commands in a terminal or command prompt: ```sh $ python3 -m venv ./venv $ source venv/bin/activate -(venv) $ pip install PyQt5 +(venv) $ pip install PyQt6 ``` -Once you have [PyQt](https://www.riverbankcomputing.com/static/Docs/PyQt5/) installed, you can run the application by executing the following command: +Once you have [PyQt](https://www.riverbankcomputing.com/static/Docs/PyQt6/) installed, you can run the application by executing the following command: ```sh (venv) $ cd sample_editor/ diff --git a/qt-designer-python/sample_editor/app.py b/qt-designer-python/sample_editor/app.py index f37347e8e5..01441197c6 100644 --- a/qt-designer-python/sample_editor/app.py +++ b/qt-designer-python/sample_editor/app.py @@ -1,8 +1,8 @@ import sys from main_window_ui import Ui_MainWindow -from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow, QMessageBox -from PyQt5.uic import loadUi +from PyQt6.QtWidgets import QApplication, QDialog, QMainWindow, QMessageBox +from PyQt6.uic import loadUi class Window(QMainWindow, Ui_MainWindow): diff --git a/qt-designer-python/sample_editor/main_window_ui.py b/qt-designer-python/sample_editor/main_window_ui.py index d62d0457cd..46059a19da 100644 --- a/qt-designer-python/sample_editor/main_window_ui.py +++ b/qt-designer-python/sample_editor/main_window_ui.py @@ -1,122 +1,88 @@ -# -*- coding: utf-8 -*- - # Form implementation generated from reading ui file 'ui/main_window.ui' # -# Created by: PyQt5 UI code generator 5.15.1 +# Created by: PyQt6 UI code generator 6.11.0 # -# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# 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 PyQt5 import QtCore, QtGui, QtWidgets +from PyQt6 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(413, 299) - self.centralwidget = QtWidgets.QWidget(MainWindow) + self.centralwidget = QtWidgets.QWidget(parent=MainWindow) self.centralwidget.setObjectName("centralwidget") self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget) self.verticalLayout.setContentsMargins(1, 1, 1, 1) self.verticalLayout.setObjectName("verticalLayout") - self.textEdit = QtWidgets.QTextEdit(self.centralwidget) + self.textEdit = QtWidgets.QTextEdit(parent=self.centralwidget) self.textEdit.setObjectName("textEdit") self.verticalLayout.addWidget(self.textEdit) MainWindow.setCentralWidget(self.centralwidget) - self.menubar = QtWidgets.QMenuBar(MainWindow) + self.menubar = QtWidgets.QMenuBar(parent=MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 413, 20)) self.menubar.setObjectName("menubar") - self.menu_File = QtWidgets.QMenu(self.menubar) + self.menu_File = QtWidgets.QMenu(parent=self.menubar) self.menu_File.setObjectName("menu_File") - self.menuOpen_Recent = QtWidgets.QMenu(self.menu_File) + self.menuOpen_Recent = QtWidgets.QMenu(parent=self.menu_File) self.menuOpen_Recent.setObjectName("menuOpen_Recent") - self.menu_Edit = QtWidgets.QMenu(self.menubar) + self.menu_Edit = QtWidgets.QMenu(parent=self.menubar) self.menu_Edit.setObjectName("menu_Edit") - self.menu_Help = QtWidgets.QMenu(self.menubar) + self.menu_Help = QtWidgets.QMenu(parent=self.menubar) self.menu_Help.setObjectName("menu_Help") MainWindow.setMenuBar(self.menubar) - self.statusbar = QtWidgets.QStatusBar(MainWindow) + self.statusbar = QtWidgets.QStatusBar(parent=MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) - self.toolBar = QtWidgets.QToolBar(MainWindow) + self.toolBar = QtWidgets.QToolBar(parent=MainWindow) self.toolBar.setObjectName("toolBar") - MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar) - self.action_New = QtWidgets.QAction(MainWindow) + MainWindow.addToolBar(QtCore.Qt.ToolBarArea.TopToolBarArea, self.toolBar) + self.action_New = QtGui.QAction(parent=MainWindow) icon = QtGui.QIcon() - icon.addPixmap( - QtGui.QPixmap("ui/resources/file-new.png"), - QtGui.QIcon.Normal, - QtGui.QIcon.Off, - ) + icon.addPixmap(QtGui.QPixmap("ui/resources/file-new.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.action_New.setIcon(icon) self.action_New.setObjectName("action_New") - self.action_Open = QtWidgets.QAction(MainWindow) + self.action_Open = QtGui.QAction(parent=MainWindow) icon1 = QtGui.QIcon() - icon1.addPixmap( - QtGui.QPixmap("ui/resources/file-open.png"), - QtGui.QIcon.Normal, - QtGui.QIcon.Off, - ) + icon1.addPixmap(QtGui.QPixmap("ui/resources/file-open.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.action_Open.setIcon(icon1) self.action_Open.setObjectName("action_Open") - self.action_Save = QtWidgets.QAction(MainWindow) + self.action_Save = QtGui.QAction(parent=MainWindow) icon2 = QtGui.QIcon() - icon2.addPixmap( - QtGui.QPixmap("ui/resources/file-save.png"), - QtGui.QIcon.Normal, - QtGui.QIcon.Off, - ) + icon2.addPixmap(QtGui.QPixmap("ui/resources/file-save.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.action_Save.setIcon(icon2) self.action_Save.setObjectName("action_Save") - self.action_Exit = QtWidgets.QAction(MainWindow) + self.action_Exit = QtGui.QAction(parent=MainWindow) icon3 = QtGui.QIcon() - icon3.addPixmap( - QtGui.QPixmap("ui/resources/file-exit.png"), - QtGui.QIcon.Normal, - QtGui.QIcon.Off, - ) + icon3.addPixmap(QtGui.QPixmap("ui/resources/file-exit.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.action_Exit.setIcon(icon3) self.action_Exit.setObjectName("action_Exit") - self.action_Copy = QtWidgets.QAction(MainWindow) + self.action_Copy = QtGui.QAction(parent=MainWindow) icon4 = QtGui.QIcon() - icon4.addPixmap( - QtGui.QPixmap("ui/resources/edit-copy.png"), - QtGui.QIcon.Normal, - QtGui.QIcon.Off, - ) + icon4.addPixmap(QtGui.QPixmap("ui/resources/edit-copy.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.action_Copy.setIcon(icon4) self.action_Copy.setObjectName("action_Copy") - self.action_Paste = QtWidgets.QAction(MainWindow) + self.action_Paste = QtGui.QAction(parent=MainWindow) icon5 = QtGui.QIcon() - icon5.addPixmap( - QtGui.QPixmap("ui/resources/edit-paste.png"), - QtGui.QIcon.Normal, - QtGui.QIcon.Off, - ) + icon5.addPixmap(QtGui.QPixmap("ui/resources/edit-paste.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.action_Paste.setIcon(icon5) self.action_Paste.setObjectName("action_Paste") - self.action_Cut = QtWidgets.QAction(MainWindow) + self.action_Cut = QtGui.QAction(parent=MainWindow) icon6 = QtGui.QIcon() - icon6.addPixmap( - QtGui.QPixmap("ui/resources/edit-cut.png"), - QtGui.QIcon.Normal, - QtGui.QIcon.Off, - ) + icon6.addPixmap(QtGui.QPixmap("ui/resources/edit-cut.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.action_Cut.setIcon(icon6) self.action_Cut.setObjectName("action_Cut") - self.actionOpen_All = QtWidgets.QAction(MainWindow) + self.actionOpen_All = QtGui.QAction(parent=MainWindow) self.actionOpen_All.setObjectName("actionOpen_All") - self.action_About = QtWidgets.QAction(MainWindow) + self.action_About = QtGui.QAction(parent=MainWindow) icon7 = QtGui.QIcon() - icon7.addPixmap( - QtGui.QPixmap("ui/resources/help-content.png"), - QtGui.QIcon.Normal, - QtGui.QIcon.Off, - ) + icon7.addPixmap(QtGui.QPixmap("ui/resources/help-content.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.action_About.setIcon(icon7) self.action_About.setObjectName("action_About") - self.action_Find_Replace = QtWidgets.QAction(MainWindow) + self.action_Find_Replace = QtGui.QAction(parent=MainWindow) self.action_Find_Replace.setObjectName("action_Find_Replace") self.menuOpen_Recent.addAction(self.actionOpen_All) self.menu_File.addAction(self.action_New) @@ -160,47 +126,27 @@ def retranslateUi(self, MainWindow): self.menu_Help.setTitle(_translate("MainWindow", "&Help")) self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar")) self.action_New.setText(_translate("MainWindow", "&New...")) - self.action_New.setToolTip( - _translate("MainWindow", "Create a New Document") - ) + self.action_New.setToolTip(_translate("MainWindow", "Create a New Document")) self.action_New.setShortcut(_translate("MainWindow", "Ctrl+N")) self.action_Open.setText(_translate("MainWindow", "&Open...")) - self.action_Open.setToolTip( - _translate("MainWindow", "Open a Document") - ) + self.action_Open.setToolTip(_translate("MainWindow", "Open a Document")) self.action_Open.setShortcut(_translate("MainWindow", "Ctrl+O")) self.action_Save.setText(_translate("MainWindow", "&Save")) - self.action_Save.setToolTip( - _translate("MainWindow", "Save the Current Document") - ) + self.action_Save.setToolTip(_translate("MainWindow", "Save the Current Document")) self.action_Save.setShortcut(_translate("MainWindow", "Ctrl+S")) self.action_Exit.setText(_translate("MainWindow", "&Exit")) self.action_Copy.setText(_translate("MainWindow", "&Copy")) - self.action_Copy.setToolTip( - _translate("MainWindow", "Copy Slected Text") - ) + self.action_Copy.setToolTip(_translate("MainWindow", "Copy Slected Text")) self.action_Copy.setShortcut(_translate("MainWindow", "Ctrl+C")) self.action_Paste.setText(_translate("MainWindow", "&Paste")) - self.action_Paste.setToolTip( - _translate("MainWindow", "Paste Copied Text") - ) + self.action_Paste.setToolTip(_translate("MainWindow", "Paste Copied Text")) self.action_Paste.setShortcut(_translate("MainWindow", "Ctrl+V")) self.action_Cut.setText(_translate("MainWindow", "C&ut")) - self.action_Cut.setToolTip( - _translate("MainWindow", "Cut Selected Text") - ) + self.action_Cut.setToolTip(_translate("MainWindow", "Cut Selected Text")) self.action_Cut.setShortcut(_translate("MainWindow", "Ctrl+X")) self.actionOpen_All.setText(_translate("MainWindow", "Open All")) - self.actionOpen_All.setToolTip( - _translate("MainWindow", "Open All Recent Documents") - ) + self.actionOpen_All.setToolTip(_translate("MainWindow", "Open All Recent Documents")) self.action_About.setText(_translate("MainWindow", "&About...")) - self.action_Find_Replace.setText( - _translate("MainWindow", "&Find and Replace...") - ) - self.action_Find_Replace.setToolTip( - _translate("MainWindow", "Launch Find and Replace Dialog") - ) - self.action_Find_Replace.setShortcut( - _translate("MainWindow", "Ctrl+F") - ) + self.action_Find_Replace.setText(_translate("MainWindow", "&Find and Replace...")) + self.action_Find_Replace.setToolTip(_translate("MainWindow", "Launch Find and Replace Dialog")) + self.action_Find_Replace.setShortcut(_translate("MainWindow", "Ctrl+F")) From 5513b4ee2e80a79664120daf1904834fcb45baaa Mon Sep 17 00:00:00 2001 From: Real Python Bot <42617967+realpython-bot@users.noreply.github.com> Date: Mon, 29 Jun 2026 20:42:05 +0200 Subject: [PATCH 2/5] Exclude generated main_window_ui.py from ruff The pyuic6-generated UI module is regenerated from main_window.ui and is not meant to be hand-formatted, so exclude it from ruff format/check, matching the existing how-to-indent sample_code.py exclude. Co-Authored-By: Claude Opus 4.8 (1M context) --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f70243817e..1f139aa471 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,8 @@ exclude = [ ".devcontainers", ".github", "migrations", - "how-to-indent-in-python/sample_code.py" + "how-to-indent-in-python/sample_code.py", + "qt-designer-python/sample_editor/main_window_ui.py" ] [tool.ruff.lint] From dfbd4ef0de108bb58e2b2d0d256b9ec1f428e8f2 Mon Sep 17 00:00:00 2001 From: Real Python Bot <42617967+realpython-bot@users.noreply.github.com> Date: Mon, 29 Jun 2026 20:53:01 +0200 Subject: [PATCH 3/5] Restructure qt-designer-python README to the standard materials format Lead with the post-materials header (normalized title + published tutorial link), then keep the app-specific run instructions and the GPL icon-license note. Co-Authored-By: Claude Opus 4.8 (1M context) --- qt-designer-python/README.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/qt-designer-python/README.md b/qt-designer-python/README.md index 9e890d16ff..792ee0ff06 100644 --- a/qt-designer-python/README.md +++ b/qt-designer-python/README.md @@ -1,30 +1,26 @@ -# Sample Text Editor +# Qt Designer and Python: Build Your GUI Applications Faster -A **sample text editor** that shows how to use Qt Designer to create GUI applications. +This folder provides the code examples for the Real Python tutorial [Qt Designer and Python: Build Your GUI Applications Faster](https://realpython.com/qt-designer-python/) -## How to Run this Application +## How to Run This Application -To run this application, you need to [install `PyQt6`](https://realpython.com/python-pyqt-gui-calculator/#installing-pyqt) on your Python environment. To do that, you can run the following commands in a terminal or command prompt: +Create and activate a Python virtual environment, then install [PyQt6](https://pypi.org/project/PyQt6/): ```sh $ python3 -m venv ./venv $ source venv/bin/activate -(venv) $ pip install PyQt6 +(venv) $ python -m pip install pyqt6 ``` -Once you have [PyQt](https://www.riverbankcomputing.com/static/Docs/PyQt6/) installed, you can run the application by executing the following command: +Then launch the sample text editor from the `sample_editor/` directory: ```sh (venv) $ cd sample_editor/ (venv) $ python app.py ``` -This command will launch the application, so you'll be able to experiment with it. - -## About the Author - -Leodanis Pozo Ramos – [@lpozo78](https://twitter.com/lpozo78) – lpozor78@gmail.com +Run `app.py` from inside `sample_editor/`, because the application loads its `.ui` files and icons through relative paths. ## License -The set of icons used in this application are part of the [TurkinOS](https://github.com/llamaret/turkinos-icon) icon theme, which is distributed under the [GPL v3.0 license](https://github.com/llamaret/turkinos-icon/blob/master/LICENSE). See `ui/resources/LICENSE` for details. \ No newline at end of file +The icons used in this application are part of the [TurkinOS](https://github.com/llamaret/turkinos-icon) icon theme, distributed under the [GPL v3.0 license](https://github.com/llamaret/turkinos-icon/blob/master/LICENSE). See `ui/resources/LICENSE` for details. From 5937d6af0df753c7ab92339d67cb061959c60c9c Mon Sep 17 00:00:00 2001 From: Real Python Bot <42617967+realpython-bot@users.noreply.github.com> Date: Mon, 29 Jun 2026 21:00:15 +0200 Subject: [PATCH 4/5] Use standard materials README at qt-designer-python root The top-level folder README now follows the post-materials format (header + tutorial link); the detailed app README moves into sample_editor/. Co-Authored-By: Claude Opus 4.8 (1M context) --- qt-designer-python/README.md | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/qt-designer-python/README.md b/qt-designer-python/README.md index 792ee0ff06..6827db3913 100644 --- a/qt-designer-python/README.md +++ b/qt-designer-python/README.md @@ -1,26 +1,3 @@ # Qt Designer and Python: Build Your GUI Applications Faster This folder provides the code examples for the Real Python tutorial [Qt Designer and Python: Build Your GUI Applications Faster](https://realpython.com/qt-designer-python/) - -## How to Run This Application - -Create and activate a Python virtual environment, then install [PyQt6](https://pypi.org/project/PyQt6/): - -```sh -$ python3 -m venv ./venv -$ source venv/bin/activate -(venv) $ python -m pip install pyqt6 -``` - -Then launch the sample text editor from the `sample_editor/` directory: - -```sh -(venv) $ cd sample_editor/ -(venv) $ python app.py -``` - -Run `app.py` from inside `sample_editor/`, because the application loads its `.ui` files and icons through relative paths. - -## License - -The icons used in this application are part of the [TurkinOS](https://github.com/llamaret/turkinos-icon) icon theme, distributed under the [GPL v3.0 license](https://github.com/llamaret/turkinos-icon/blob/master/LICENSE). See `ui/resources/LICENSE` for details. From 58ef43d3eb80daccdba81a38e85168bc8c62f0fe Mon Sep 17 00:00:00 2001 From: Real Python Bot <42617967+realpython-bot@users.noreply.github.com> Date: Mon, 29 Jun 2026 21:00:16 +0200 Subject: [PATCH 5/5] Add app README inside sample_editor/ Moves the original Sample Text Editor README (run instructions, author, GPL icon license) next to app.py, where its relative paths resolve. Co-Authored-By: Claude Opus 4.8 (1M context) --- qt-designer-python/sample_editor/README.md | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 qt-designer-python/sample_editor/README.md diff --git a/qt-designer-python/sample_editor/README.md b/qt-designer-python/sample_editor/README.md new file mode 100644 index 0000000000..157084acb6 --- /dev/null +++ b/qt-designer-python/sample_editor/README.md @@ -0,0 +1,29 @@ +# Sample Text Editor + +A **sample text editor** that shows how to use Qt Designer to create GUI applications. + +## How to Run this Application + +To run this application, you need to [install `PyQt6`](https://realpython.com/python-pyqt-gui-calculator/#installing-pyqt) on your Python environment. To do that, you can run the following commands in a terminal or command prompt: + +```sh +$ python3 -m venv ./venv +$ source venv/bin/activate +(venv) $ pip install PyQt6 +``` + +Once you have [PyQt](https://www.riverbankcomputing.com/static/Docs/PyQt6/) installed, you can run the application by executing the following command: + +```sh +(venv) $ python app.py +``` + +This command will launch the application, so you'll be able to experiment with it. + +## About the Author + +Leodanis Pozo Ramos – [@lpozo78](https://twitter.com/lpozo78) – lpozor78@gmail.com + +## License + +The set of icons used in this application are part of the [TurkinOS](https://github.com/llamaret/turkinos-icon) icon theme, which is distributed under the [GPL v3.0 license](https://github.com/llamaret/turkinos-icon/blob/master/LICENSE). See `ui/resources/LICENSE` for details.