From 8bd8895599c31b36292493f51389881efc07f130 Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Sat, 26 Aug 2023 14:27:09 +0800 Subject: [PATCH 1/9] QMessageBox upgrade version --- src/07 Qt Text Editor/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/07 Qt Text Editor/main.py b/src/07 Qt Text Editor/main.py index fe498584..13623697 100644 --- a/src/07 Qt Text Editor/main.py +++ b/src/07 Qt Text Editor/main.py @@ -8,16 +8,17 @@ def closeEvent(self, e): answer = QMessageBox.question( window, None, "You have unsaved changes. Save before closing?", - QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel + QMessageBox.StandardButton.Save | QMessageBox.StandardButton.Discard \ + | QMessageBox.StandardButton.Cancel ) - if answer & QMessageBox.Save: + if answer & QMessageBox.StandardButton.Save: save() if text.document().isModified(): # This happens when the user closes the Save As... dialog. # We do not want to close the window in this case because it # would throw away unsaved changes. e.ignore() - elif answer & QMessageBox.Cancel: + elif answer & QMessageBox.StandardButton.Cancel: e.ignore() app = QApplication([]) From 63ec135173c641718b402cefd704fda4e58ba13c Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Sat, 26 Aug 2023 15:17:19 +0800 Subject: [PATCH 2/9] upgrade version --- src/08 PyQt6 exe/src/main/python/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/08 PyQt6 exe/src/main/python/main.py b/src/08 PyQt6 exe/src/main/python/main.py index c07724f5..ca1b4896 100644 --- a/src/08 PyQt6 exe/src/main/python/main.py +++ b/src/08 PyQt6 exe/src/main/python/main.py @@ -6,7 +6,7 @@ appctxt = ApplicationContext() # 1. Instantiate ApplicationContext from PyQt6.QtWidgets import * -from PyQt6.QtGui import QKeySequence +from PyQt6.QtGui import QKeySequence, QAction class MainWindow(QMainWindow): def closeEvent(self, e): @@ -15,11 +15,11 @@ def closeEvent(self, e): answer = QMessageBox.question( window, None, "You have unsaved changes. Save before closing?", - QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel + QMessageBox.StandardButton.Save | QMessageBox.StandardButton.Discard | QMessageBox.StandardButton.Cancel ) - if answer & QMessageBox.Save: + if answer & QMessageBox.StandardButton.Save: save() - elif answer & QMessageBox.Cancel: + elif answer & QMessageBox.StandardButton.Cancel: e.ignore() text = QPlainTextEdit() @@ -37,7 +37,7 @@ def open_file(): text.setPlainText(open(path).read()) file_path = path open_action.triggered.connect(open_file) -open_action.setShortcut(QKeySequence.Open) +open_action.setShortcut(QKeySequence.StandardKey.Open) menu.addAction(open_action) save_action = QAction("&Save") @@ -49,7 +49,7 @@ def save(): f.write(text.toPlainText()) text.document().setModified(False) save_action.triggered.connect(save) -save_action.setShortcut(QKeySequence.Save) +save_action.setShortcut(QKeySequence.StandardKey.Save) menu.addAction(save_action) save_as_action = QAction("Save &As...") From a00d5824ce4731e5633d7aec89aca4140836a09c Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Sat, 26 Aug 2023 15:23:23 +0800 Subject: [PATCH 3/9] upgrade version --- src/09 Qt dark theme/main.py | 39 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/09 Qt dark theme/main.py b/src/09 Qt dark theme/main.py index a405db27..b54d2106 100644 --- a/src/09 Qt dark theme/main.py +++ b/src/09 Qt dark theme/main.py @@ -1,5 +1,5 @@ from PyQt6.QtWidgets import * -from PyQt6.QtGui import QKeySequence, QPalette, QColor +from PyQt6.QtGui import QKeySequence, QPalette, QColor, QAction from PyQt6.QtCore import Qt app = QApplication([]) @@ -9,19 +9,19 @@ # Now use a palette to switch to dark colors: palette = QPalette() -palette.setColor(QPalette.Window, QColor(53, 53, 53)) -palette.setColor(QPalette.WindowText, Qt.white) -palette.setColor(QPalette.Base, QColor(25, 25, 25)) -palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53)) -palette.setColor(QPalette.ToolTipBase, Qt.white) -palette.setColor(QPalette.ToolTipText, Qt.white) -palette.setColor(QPalette.Text, Qt.white) -palette.setColor(QPalette.Button, QColor(53, 53, 53)) -palette.setColor(QPalette.ButtonText, Qt.white) -palette.setColor(QPalette.BrightText, Qt.red) -palette.setColor(QPalette.Link, QColor(42, 130, 218)) -palette.setColor(QPalette.Highlight, QColor(42, 130, 218)) -palette.setColor(QPalette.HighlightedText, Qt.black) +palette.setColor(QPalette.ColorRole.Window, QColor(53, 53, 53)) +palette.setColor(QPalette.ColorRole.WindowText, Qt.GlobalColor.white) +palette.setColor(QPalette.ColorRole.Base, QColor(25, 25, 25)) +palette.setColor(QPalette.ColorRole.AlternateBase, QColor(53, 53, 53)) +palette.setColor(QPalette.ColorRole.ToolTipBase, Qt.GlobalColor.white) +palette.setColor(QPalette.ColorRole.ToolTipText, Qt.GlobalColor.white) +palette.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.white) +palette.setColor(QPalette.ColorRole.Button, QColor(53, 53, 53)) +palette.setColor(QPalette.ColorRole.ButtonText, Qt.GlobalColor.white) +palette.setColor(QPalette.ColorRole.BrightText, Qt.GlobalColor.red) +palette.setColor(QPalette.ColorRole.Link, QColor(42, 130, 218)) +palette.setColor(QPalette.ColorRole.Highlight, QColor(42, 130, 218)) +palette.setColor(QPalette.ColorRole.HighlightedText, Qt.GlobalColor.black) app.setPalette(palette) # The rest of the code is the same as for the "normal" text editor. @@ -37,11 +37,12 @@ def closeEvent(self, e): answer = QMessageBox.question( window, None, "You have unsaved changes. Save before closing?", - QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel + QMessageBox.StandardButton.Save | QMessageBox.StandardButton.Discard \ + | QMessageBox.StandardButton.Cancel ) - if answer & QMessageBox.Save: + if answer & QMessageBox.StandardButton.Save: save() - elif answer & QMessageBox.Cancel: + elif answer & QMessageBox.StandardButton.Cancel: e.ignore() window = MainWindow() @@ -58,7 +59,7 @@ def open_file(): text.setPlainText(open(path).read()) file_path = path open_action.triggered.connect(open_file) -open_action.setShortcut(QKeySequence.Open) +open_action.setShortcut(QKeySequence.StandardKey.Open) menu.addAction(open_action) save_action = QAction("&Save") @@ -70,7 +71,7 @@ def save(): f.write(text.toPlainText()) text.document().setModified(False) save_action.triggered.connect(save) -save_action.setShortcut(QKeySequence.Save) +save_action.setShortcut(QKeySequence.StandardKey.Save) menu.addAction(save_action) save_as_action = QAction("Save &As...") From 568cc7ef20596b3140a223d71b02c2f50949f058 Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Sat, 26 Aug 2023 16:12:33 +0800 Subject: [PATCH 4/9] upgrade 10 QPainter Python example --- src/10 QPainter Python example/main.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/10 QPainter Python example/main.py b/src/10 QPainter Python example/main.py index 3144fc1b..6d9f13f4 100644 --- a/src/10 QPainter Python example/main.py +++ b/src/10 QPainter Python example/main.py @@ -1,7 +1,7 @@ from PyQt6.QtWidgets import * from PyQt6.QtGui import * from PyQt6.QtCore import * -from PyQt6.QtMultimedia import QSound +from PyQt6.QtMultimedia import QSoundEffect class PlainTextEdit(QPlainTextEdit): def __init__(self): @@ -9,12 +9,15 @@ def __init__(self): self._holes = [] self._bullet = QPixmap("bullet.png") size = self._bullet.size() - self._offset = QPoint(size.width() / 2, size.height() / 2) + self._offset = QPoint(size.width() // 2, size.height() // 2) + self.effect = QSoundEffect() + self.effect.setSource(QUrl.fromLocalFile("shot.wav")) + self.effect.setVolume(0.26) def mousePressEvent(self, e): self._holes.append(e.pos()) super().mousePressEvent(e) self.viewport().update() - QSound.play("shot.wav") + self.effect.play() def paintEvent(self, e): super().paintEvent(e) painter = QPainter(self.viewport()) @@ -34,11 +37,12 @@ def closeEvent(self, e): answer = QMessageBox.question( window, None, "You have unsaved changes. Save before closing?", - QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel + QMessageBox.StandardButton.Save | QMessageBox.StandardButton.Discard \ + | QMessageBox.StandardButton.Cancel ) - if answer & QMessageBox.Save: + if answer & QMessageBox.StandardButton.Save: save() - elif answer & QMessageBox.Cancel: + elif answer & QMessageBox.StandardButton.Cancel: e.ignore() app.setApplicationName("Text Editor") @@ -56,7 +60,7 @@ def open_file(): text.setPlainText(open(path).read()) file_path = path open_action.triggered.connect(open_file) -open_action.setShortcut(QKeySequence.Open) +open_action.setShortcut(QKeySequence.StandardKey.Open) menu.addAction(open_action) save_action = QAction("&Save") @@ -68,7 +72,7 @@ def save(): f.write(text.toPlainText()) text.document().setModified(False) save_action.triggered.connect(save) -save_action.setShortcut(QKeySequence.Save) +save_action.setShortcut(QKeySequence.StandardKey.Save) menu.addAction(save_action) save_as_action = QAction("Save &As...") From bf32e9b8c162069e4a6a1692b1b166b204491540 Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Sat, 26 Aug 2023 16:45:43 +0800 Subject: [PATCH 5/9] upgrade 11 PyQt Thread example --- src/11 PyQt Thread example/01_single_threaded.py | 2 +- src/11 PyQt Thread example/02_multithreaded.py | 2 +- src/11 PyQt Thread example/03_with_threadutil.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/11 PyQt Thread example/01_single_threaded.py b/src/11 PyQt Thread example/01_single_threaded.py index 533674f6..e7333afd 100644 --- a/src/11 PyQt Thread example/01_single_threaded.py +++ b/src/11 PyQt Thread example/01_single_threaded.py @@ -9,7 +9,7 @@ # GUI: app = QApplication([]) text_area = QPlainTextEdit() -text_area.setFocusPolicy(Qt.NoFocus) +text_area.setFocusPolicy(Qt.FocusPolicy.NoFocus) message = QLineEdit() layout = QVBoxLayout() layout.addWidget(text_area) diff --git a/src/11 PyQt Thread example/02_multithreaded.py b/src/11 PyQt Thread example/02_multithreaded.py index dcfa85a9..2d408f10 100644 --- a/src/11 PyQt Thread example/02_multithreaded.py +++ b/src/11 PyQt Thread example/02_multithreaded.py @@ -11,7 +11,7 @@ # GUI: app = QApplication([]) text_area = QPlainTextEdit() -text_area.setFocusPolicy(Qt.NoFocus) +text_area.setFocusPolicy(Qt.FocusPolicy.NoFocus) message = QLineEdit() layout = QVBoxLayout() layout.addWidget(text_area) diff --git a/src/11 PyQt Thread example/03_with_threadutil.py b/src/11 PyQt Thread example/03_with_threadutil.py index 69cdd480..81daa95f 100644 --- a/src/11 PyQt Thread example/03_with_threadutil.py +++ b/src/11 PyQt Thread example/03_with_threadutil.py @@ -12,7 +12,7 @@ # GUI: app = QApplication([]) text_area = QPlainTextEdit() -text_area.setFocusPolicy(Qt.NoFocus) +text_area.setFocusPolicy(Qt.FocusPolicy.NoFocus) message = QLineEdit() layout = QVBoxLayout() layout.addWidget(text_area) From 117bdc3853a6ab955d8ab3f0a46c60ee5bb862a4 Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Sat, 26 Aug 2023 19:54:36 +0800 Subject: [PATCH 6/9] upgrade 12 QTreeView example in Python --- src/12 QTreeView example in Python/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/12 QTreeView example in Python/main.py b/src/12 QTreeView example in Python/main.py index 0fc268a2..b029ae00 100644 --- a/src/12 QTreeView example in Python/main.py +++ b/src/12 QTreeView example in Python/main.py @@ -1,10 +1,11 @@ from os.path import expanduser -from PyQt6.QtWidgets import * +from PySide6.QtWidgets import QApplication, QTreeView, QFileSystemModel home_directory = expanduser('~') app = QApplication([]) -model = QDirModel() +model = QFileSystemModel() +model.setRootPath(home_directory) view = QTreeView() view.setModel(model) view.setRootIndex(model.index(home_directory)) From 31de9cebdb9676377b35b42c557bafbe8973f028 Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Sat, 26 Aug 2023 20:08:57 +0800 Subject: [PATCH 7/9] 12 QTreeView example in Python need PySide6 --- src/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/requirements.txt b/src/requirements.txt index baa951b9..81560037 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,3 +1,4 @@ fbs PyQt6 +PySide6 requests From c9fc6750920b94f6d03968ca2ad56e49d25a828c Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Sun, 27 Aug 2023 08:31:59 +0800 Subject: [PATCH 8/9] Revert "upgrade 12 QTreeView example in Python" This reverts commit 117bdc3853a6ab955d8ab3f0a46c60ee5bb862a4. --- src/12 QTreeView example in Python/main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/12 QTreeView example in Python/main.py b/src/12 QTreeView example in Python/main.py index b029ae00..0fc268a2 100644 --- a/src/12 QTreeView example in Python/main.py +++ b/src/12 QTreeView example in Python/main.py @@ -1,11 +1,10 @@ from os.path import expanduser -from PySide6.QtWidgets import QApplication, QTreeView, QFileSystemModel +from PyQt6.QtWidgets import * home_directory = expanduser('~') app = QApplication([]) -model = QFileSystemModel() -model.setRootPath(home_directory) +model = QDirModel() view = QTreeView() view.setModel(model) view.setRootIndex(model.index(home_directory)) From 1945313af6708cb4bba0cb99851a8607682474cf Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Sun, 27 Aug 2023 08:32:38 +0800 Subject: [PATCH 9/9] Revert "12 QTreeView example in Python need PySide6" This reverts commit 31de9cebdb9676377b35b42c557bafbe8973f028. --- src/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/requirements.txt b/src/requirements.txt index 81560037..baa951b9 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,4 +1,3 @@ fbs PyQt6 -PySide6 requests