From 4265297f2e44cfaab131966366821a34759a6364 Mon Sep 17 00:00:00 2001 From: stsav012 Date: Fri, 3 Mar 2023 18:37:33 +0300 Subject: [PATCH 1/2] Provide what has been moved to between QtWidgets and QtGui in Qt6 --- qtpy/QtGui.py | 7 +++++++ qtpy/tests/test_qtgui.py | 9 +++++++++ qtpy/tests/test_qtwidgets.py | 10 +++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 86502fd2..4c762c63 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -12,6 +12,9 @@ if PYQT5: from PyQt5.QtGui import * + # Backport items moved to QtGui in Qt6 + from PyQt5.QtWidgets import QAction, QActionGroup, QFileSystemModel, QShortcut, QUndoCommand + elif PYQT6: from PyQt6 import QtGui from PyQt6.QtGui import * @@ -30,12 +33,16 @@ del QtGui elif PYSIDE2: from PySide2.QtGui import * + # Backport items moved to QtGui in Qt6 + from PySide2.QtWidgets import QAction, QActionGroup, QFileSystemModel, QShortcut, QUndoCommand if hasattr(QFontMetrics, 'horizontalAdvance'): # Needed to prevent raising a DeprecationWarning when using QFontMetrics.width QFontMetrics.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs) elif PYSIDE6: from PySide6.QtGui import * from PySide6.QtOpenGL import * + # Backport `QFileSystemModel` moved to QtGui in Qt6 + from PySide6.QtWidgets import QFileSystemModel QFontMetrics.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs) QFontMetricsF.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs) diff --git a/qtpy/tests/test_qtgui.py b/qtpy/tests/test_qtgui.py index d16f08a2..787d7dba 100644 --- a/qtpy/tests/test_qtgui.py +++ b/qtpy/tests/test_qtgui.py @@ -39,6 +39,15 @@ def test_qguiapplication_functions(): assert QtGui.QGuiApplication.exec_ is not None +def test_what_moved_to_qtgui_in_qt6(): + """Test what has been moved to QtGui in Qt6""" + assert QtGui.QAction is not None + assert QtGui.QActionGroup is not None + assert QtGui.QFileSystemModel is not None + assert QtGui.QShortcut is not None + assert QtGui.QUndoCommand is not None + + @pytest.mark.skipif( sys.platform.startswith('linux') and not_using_conda(), reason="Segmentation fault/Aborted on Linux CI when not using conda") diff --git a/qtpy/tests/test_qtwidgets.py b/qtpy/tests/test_qtwidgets.py index a04e662d..8670fdf6 100644 --- a/qtpy/tests/test_qtwidgets.py +++ b/qtpy/tests/test_qtwidgets.py @@ -29,9 +29,13 @@ def test_qlineedit_functions(): assert QtWidgets.QLineEdit.getTextMargins -def test_qundocommand_object(): - """Test object aliasing for QUndoCommand""" - assert QtWidgets.QUndoCommand +def test_what_moved_to_qtgui_in_qt6(): + """Test that we move back what has been moved to QtGui in Qt6""" + assert QtWidgets.QAction is not None + assert QtWidgets.QActionGroup is not None + assert QtWidgets.QFileSystemModel is not None + assert QtWidgets.QShortcut is not None + assert QtWidgets.QUndoCommand is not None @pytest.mark.skipif( From 5c6dd9c0b2659dc9381a27ac002166f80626d243 Mon Sep 17 00:00:00 2001 From: Anton Yablokov Date: Sat, 18 Mar 2023 19:31:49 +0300 Subject: [PATCH 2/2] Add blank lines for better readability, as suggested by @ccordoba12 Co-authored-by: Carlos Cordoba --- qtpy/QtGui.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 4c762c63..35a83eab 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -12,9 +12,9 @@ if PYQT5: from PyQt5.QtGui import * + # Backport items moved to QtGui in Qt6 from PyQt5.QtWidgets import QAction, QActionGroup, QFileSystemModel, QShortcut, QUndoCommand - elif PYQT6: from PyQt6 import QtGui from PyQt6.QtGui import * @@ -33,16 +33,20 @@ del QtGui elif PYSIDE2: from PySide2.QtGui import * + # Backport items moved to QtGui in Qt6 from PySide2.QtWidgets import QAction, QActionGroup, QFileSystemModel, QShortcut, QUndoCommand + if hasattr(QFontMetrics, 'horizontalAdvance'): # Needed to prevent raising a DeprecationWarning when using QFontMetrics.width QFontMetrics.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs) elif PYSIDE6: from PySide6.QtGui import * from PySide6.QtOpenGL import * + # Backport `QFileSystemModel` moved to QtGui in Qt6 from PySide6.QtWidgets import QFileSystemModel + QFontMetrics.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs) QFontMetricsF.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs)