Skip to content

Commit

Permalink
PR: Restore Qt.ItemFlags access as Qt.ItemFlag alias (PyQt6) (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 authored Aug 17, 2023
2 parents 3ba97e3 + 9348591 commit 4039ce0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions qtpy/QtCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@
# Alias deprecated ItemDataRole enum values removed in Qt6
Qt.BackgroundColorRole = Qt.ItemDataRole.BackgroundColorRole = Qt.BackgroundRole
Qt.TextColorRole = Qt.ItemDataRole.TextColorRole = Qt.ForegroundRole

# Alias for MiddleButton removed in PyQt6 but available in PyQt5, PySide2 and PySide6
Qt.MidButton = Qt.MiddleButton

# Add removed definition for `Qt.ItemFlags` as an alias of `Qt.ItemFlag` as PySide6 does.
# Note that for PyQt5 and PySide2 those definitions are two different classes
# (one is the flag definition and the other the enum definition)
Qt.ItemFlags = Qt.ItemFlag

elif PYSIDE2:
from PySide2.QtCore import *

Expand Down
8 changes: 7 additions & 1 deletion qtpy/tests/test_qtcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def test_enum_access():
assert QtCore.Qt.TextColorRole == QtCore.Qt.ItemDataRole.TextColorRole
assert QtCore.Qt.MidButton == QtCore.Qt.MouseButton.MiddleButton


@pytest.mark.skipif(PYSIDE2 and PYSIDE_VERSION.startswith('5.12.0'),
reason="Utility functions unavailable for PySide2 5.12.0")
def test_qtgui_namespace_mightBeRichText():
Expand All @@ -156,3 +155,10 @@ def test_qtgui_namespace_mightBeRichText():
See: https://doc.qt.io/qt-5/qt-sub-qtgui.html
"""
assert QtCore.Qt.mightBeRichText is not None


def test_itemflags_typedef():
"""
Test existence of `QFlags<ItemFlag>` typedef `ItemFlags` that was removed from PyQt6
"""
assert QtCore.Qt.ItemFlags is not None

0 comments on commit 4039ce0

Please sign in to comment.