Skip to content

Commit

Permalink
QVariant.Type, Qt.ItemFlag and Qt.CheckState need to be int compatible
Browse files Browse the repository at this point in the history
For reasons(?) these aren't IntEnums/IntFlags on PyQt6, but we need
them to be int compatible for compatibility with PyQt5 code
  • Loading branch information
nyalldawson authored and troopa81 committed Feb 26, 2024
1 parent 01fc784 commit ec1b4f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .ci/test_blocklist_qt6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ PyQgsPythonProvider
PyQgsAnnotation
PyQgsAuthenticationSystem
PyQgsBlockingProcess
PyQgsBookmarkModel
PyQgsCodeEditor
PyQgsDelimitedTextProvider
PyQgsEditWidgets
PyQgsElevationProfileCanvas
PyQgsProject
PyQgsFieldModel
PyQgsFloatingWidget
PyQgsJsonUtils
PyQgsLayoutHtml
Expand Down
14 changes: 14 additions & 0 deletions python/PyQt/PyQt/QtCore.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ if (QT_VERSION >= 0x060000):
QVariant.SizePolicy = QMetaType.Type.QSizePolicy
QVariant.UserType = QMetaType.Type.User

from enum import Enum


def _force_int(v): return int(v.value) if isinstance(v, Enum) else v

QMetaType.Type.__int__ = _force_int
QMetaType.Type.__eq__ = lambda t1, t2: _force_int(t1) == _force_int(t2)

# These types aren't IntEnums or IntFlags, so patch that back in
Qt.ItemFlag.__int__ = _force_int
Qt.ItemFlag.__eq__ = lambda t1, t2: _force_int(t1) == _force_int(t2)
Qt.CheckState.__int__ = _force_int
Qt.CheckState.__eq__ = lambda t1, t2: _force_int(t1) == _force_int(t2)

# patch back in Qt flags removed in PyQt

QAbstractItemModel.CheckIndexOptions = lambda flags=0: QAbstractItemModel.CheckIndexOption(flags)
Expand Down

0 comments on commit ec1b4f8

Please sign in to comment.