Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Improve compatibility for QtWidgets and QtGui modules between Qt5 and Qt6 bindings #410

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -30,12 +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
StSav012 marked this conversation as resolved.
Show resolved Hide resolved

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
StSav012 marked this conversation as resolved.
Show resolved Hide resolved

QFontMetrics.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs)
QFontMetricsF.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs)

Expand Down
9 changes: 9 additions & 0 deletions qtpy/tests/test_qtgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 7 additions & 3 deletions qtpy/tests/test_qtwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down