Skip to content

Commit cbf5c35

Browse files
lpozoclaudebzaczynski
authored
Sample code for: Qt Designer and Python: Build Your GUI Applications Faster (#790)
Update the sample text editor from PyQt5 to PyQt6 (app.py and the pyuic6-generated main_window_ui.py), add a standard top-level README plus a detailed app README in sample_editor/, and commit the generated module in ruff-formatted form so CI passes without linter-config changes. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Bartosz Zaczyński <bartosz.zaczynski@gmail.com>
1 parent d2ee4bd commit cbf5c35

4 files changed

Lines changed: 74 additions & 72 deletions

File tree

qt-designer-python/README.md

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
# Sample Text Editor
1+
# Qt Designer and Python: Build Your GUI Applications Faster
22

3-
A **sample text editor** that shows how to use Qt Designer to create GUI applications.
4-
5-
## How to Run this Application
6-
7-
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:
8-
9-
```sh
10-
$ python3 -m venv ./venv
11-
$ source venv/bin/activate
12-
(venv) $ pip install PyQt5
13-
```
14-
15-
Once you have [PyQt](https://www.riverbankcomputing.com/static/Docs/PyQt5/) installed, you can run the application by executing the following command:
16-
17-
```sh
18-
(venv) $ cd sample_editor/
19-
(venv) $ python app.py
20-
```
21-
22-
This command will launch the application, so you'll be able to experiment with it.
23-
24-
## About the Author
25-
26-
Leodanis Pozo Ramos – [@lpozo78](https://twitter.com/lpozo78)lpozor78@gmail.com
27-
28-
## License
29-
30-
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.
3+
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/)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Sample Text Editor
2+
3+
A **sample text editor** that shows how to use Qt Designer to create GUI applications.
4+
5+
## How to Run this Application
6+
7+
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:
8+
9+
```sh
10+
$ python3 -m venv ./venv
11+
$ source venv/bin/activate
12+
(venv) $ pip install PyQt6
13+
```
14+
15+
Once you have [PyQt](https://www.riverbankcomputing.com/static/Docs/PyQt6/) installed, you can run the application by executing the following command:
16+
17+
```sh
18+
(venv) $ python app.py
19+
```
20+
21+
This command will launch the application, so you'll be able to experiment with it.
22+
23+
## About the Author
24+
25+
Leodanis Pozo Ramos – [@lpozo78](https://twitter.com/lpozo78)lpozor78@gmail.com
26+
27+
## License
28+
29+
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.txt` for details.

qt-designer-python/sample_editor/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import sys
22

33
from main_window_ui import Ui_MainWindow
4-
from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow, QMessageBox
5-
from PyQt5.uic import loadUi
4+
from PyQt6.QtWidgets import QApplication, QDialog, QMainWindow, QMessageBox
5+
from PyQt6.uic import loadUi
66

77

88
class Window(QMainWindow, Ui_MainWindow):

qt-designer-python/sample_editor/main_window_ui.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,122 @@
1-
# -*- coding: utf-8 -*-
2-
31
# Form implementation generated from reading ui file 'ui/main_window.ui'
42
#
5-
# Created by: PyQt5 UI code generator 5.15.1
3+
# Created by: PyQt6 UI code generator 6.11.0
64
#
7-
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
5+
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
86
# run again. Do not edit this file unless you know what you are doing.
97

108

11-
from PyQt5 import QtCore, QtGui, QtWidgets
9+
from PyQt6 import QtCore, QtGui, QtWidgets
1210

1311

1412
class Ui_MainWindow(object):
1513
def setupUi(self, MainWindow):
1614
MainWindow.setObjectName("MainWindow")
1715
MainWindow.resize(413, 299)
18-
self.centralwidget = QtWidgets.QWidget(MainWindow)
16+
self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
1917
self.centralwidget.setObjectName("centralwidget")
2018
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
2119
self.verticalLayout.setContentsMargins(1, 1, 1, 1)
2220
self.verticalLayout.setObjectName("verticalLayout")
23-
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
21+
self.textEdit = QtWidgets.QTextEdit(parent=self.centralwidget)
2422
self.textEdit.setObjectName("textEdit")
2523
self.verticalLayout.addWidget(self.textEdit)
2624
MainWindow.setCentralWidget(self.centralwidget)
27-
self.menubar = QtWidgets.QMenuBar(MainWindow)
25+
self.menubar = QtWidgets.QMenuBar(parent=MainWindow)
2826
self.menubar.setGeometry(QtCore.QRect(0, 0, 413, 20))
2927
self.menubar.setObjectName("menubar")
30-
self.menu_File = QtWidgets.QMenu(self.menubar)
28+
self.menu_File = QtWidgets.QMenu(parent=self.menubar)
3129
self.menu_File.setObjectName("menu_File")
32-
self.menuOpen_Recent = QtWidgets.QMenu(self.menu_File)
30+
self.menuOpen_Recent = QtWidgets.QMenu(parent=self.menu_File)
3331
self.menuOpen_Recent.setObjectName("menuOpen_Recent")
34-
self.menu_Edit = QtWidgets.QMenu(self.menubar)
32+
self.menu_Edit = QtWidgets.QMenu(parent=self.menubar)
3533
self.menu_Edit.setObjectName("menu_Edit")
36-
self.menu_Help = QtWidgets.QMenu(self.menubar)
34+
self.menu_Help = QtWidgets.QMenu(parent=self.menubar)
3735
self.menu_Help.setObjectName("menu_Help")
3836
MainWindow.setMenuBar(self.menubar)
39-
self.statusbar = QtWidgets.QStatusBar(MainWindow)
37+
self.statusbar = QtWidgets.QStatusBar(parent=MainWindow)
4038
self.statusbar.setObjectName("statusbar")
4139
MainWindow.setStatusBar(self.statusbar)
42-
self.toolBar = QtWidgets.QToolBar(MainWindow)
40+
self.toolBar = QtWidgets.QToolBar(parent=MainWindow)
4341
self.toolBar.setObjectName("toolBar")
44-
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
45-
self.action_New = QtWidgets.QAction(MainWindow)
42+
MainWindow.addToolBar(
43+
QtCore.Qt.ToolBarArea.TopToolBarArea, self.toolBar
44+
)
45+
self.action_New = QtGui.QAction(parent=MainWindow)
4646
icon = QtGui.QIcon()
4747
icon.addPixmap(
4848
QtGui.QPixmap("ui/resources/file-new.png"),
49-
QtGui.QIcon.Normal,
50-
QtGui.QIcon.Off,
49+
QtGui.QIcon.Mode.Normal,
50+
QtGui.QIcon.State.Off,
5151
)
5252
self.action_New.setIcon(icon)
5353
self.action_New.setObjectName("action_New")
54-
self.action_Open = QtWidgets.QAction(MainWindow)
54+
self.action_Open = QtGui.QAction(parent=MainWindow)
5555
icon1 = QtGui.QIcon()
5656
icon1.addPixmap(
5757
QtGui.QPixmap("ui/resources/file-open.png"),
58-
QtGui.QIcon.Normal,
59-
QtGui.QIcon.Off,
58+
QtGui.QIcon.Mode.Normal,
59+
QtGui.QIcon.State.Off,
6060
)
6161
self.action_Open.setIcon(icon1)
6262
self.action_Open.setObjectName("action_Open")
63-
self.action_Save = QtWidgets.QAction(MainWindow)
63+
self.action_Save = QtGui.QAction(parent=MainWindow)
6464
icon2 = QtGui.QIcon()
6565
icon2.addPixmap(
6666
QtGui.QPixmap("ui/resources/file-save.png"),
67-
QtGui.QIcon.Normal,
68-
QtGui.QIcon.Off,
67+
QtGui.QIcon.Mode.Normal,
68+
QtGui.QIcon.State.Off,
6969
)
7070
self.action_Save.setIcon(icon2)
7171
self.action_Save.setObjectName("action_Save")
72-
self.action_Exit = QtWidgets.QAction(MainWindow)
72+
self.action_Exit = QtGui.QAction(parent=MainWindow)
7373
icon3 = QtGui.QIcon()
7474
icon3.addPixmap(
7575
QtGui.QPixmap("ui/resources/file-exit.png"),
76-
QtGui.QIcon.Normal,
77-
QtGui.QIcon.Off,
76+
QtGui.QIcon.Mode.Normal,
77+
QtGui.QIcon.State.Off,
7878
)
7979
self.action_Exit.setIcon(icon3)
8080
self.action_Exit.setObjectName("action_Exit")
81-
self.action_Copy = QtWidgets.QAction(MainWindow)
81+
self.action_Copy = QtGui.QAction(parent=MainWindow)
8282
icon4 = QtGui.QIcon()
8383
icon4.addPixmap(
8484
QtGui.QPixmap("ui/resources/edit-copy.png"),
85-
QtGui.QIcon.Normal,
86-
QtGui.QIcon.Off,
85+
QtGui.QIcon.Mode.Normal,
86+
QtGui.QIcon.State.Off,
8787
)
8888
self.action_Copy.setIcon(icon4)
8989
self.action_Copy.setObjectName("action_Copy")
90-
self.action_Paste = QtWidgets.QAction(MainWindow)
90+
self.action_Paste = QtGui.QAction(parent=MainWindow)
9191
icon5 = QtGui.QIcon()
9292
icon5.addPixmap(
9393
QtGui.QPixmap("ui/resources/edit-paste.png"),
94-
QtGui.QIcon.Normal,
95-
QtGui.QIcon.Off,
94+
QtGui.QIcon.Mode.Normal,
95+
QtGui.QIcon.State.Off,
9696
)
9797
self.action_Paste.setIcon(icon5)
9898
self.action_Paste.setObjectName("action_Paste")
99-
self.action_Cut = QtWidgets.QAction(MainWindow)
99+
self.action_Cut = QtGui.QAction(parent=MainWindow)
100100
icon6 = QtGui.QIcon()
101101
icon6.addPixmap(
102102
QtGui.QPixmap("ui/resources/edit-cut.png"),
103-
QtGui.QIcon.Normal,
104-
QtGui.QIcon.Off,
103+
QtGui.QIcon.Mode.Normal,
104+
QtGui.QIcon.State.Off,
105105
)
106106
self.action_Cut.setIcon(icon6)
107107
self.action_Cut.setObjectName("action_Cut")
108-
self.actionOpen_All = QtWidgets.QAction(MainWindow)
108+
self.actionOpen_All = QtGui.QAction(parent=MainWindow)
109109
self.actionOpen_All.setObjectName("actionOpen_All")
110-
self.action_About = QtWidgets.QAction(MainWindow)
110+
self.action_About = QtGui.QAction(parent=MainWindow)
111111
icon7 = QtGui.QIcon()
112112
icon7.addPixmap(
113113
QtGui.QPixmap("ui/resources/help-content.png"),
114-
QtGui.QIcon.Normal,
115-
QtGui.QIcon.Off,
114+
QtGui.QIcon.Mode.Normal,
115+
QtGui.QIcon.State.Off,
116116
)
117117
self.action_About.setIcon(icon7)
118118
self.action_About.setObjectName("action_About")
119-
self.action_Find_Replace = QtWidgets.QAction(MainWindow)
119+
self.action_Find_Replace = QtGui.QAction(parent=MainWindow)
120120
self.action_Find_Replace.setObjectName("action_Find_Replace")
121121
self.menuOpen_Recent.addAction(self.actionOpen_All)
122122
self.menu_File.addAction(self.action_New)

0 commit comments

Comments
 (0)