diff --git a/qt/aqt/browser/table/model.py b/qt/aqt/browser/table/model.py index e1ff290a6..6d50d6174 100644 --- a/qt/aqt/browser/table/model.py +++ b/qt/aqt/browser/table/model.py @@ -309,13 +309,15 @@ class DataModel(QAbstractTableModel): return 0 return self.len_columns() + _QFont = without_qt5_compat_wrapper(QFont) + def data(self, index: QModelIndex = QModelIndex(), role: int = 0) -> Any: if not index.isValid(): return QVariant() if role == Qt.ItemDataRole.FontRole: if not self.column_at(index).uses_cell_font: return QVariant() - qfont = QFont() + qfont = self._QFont() row = self.get_row(index) qfont.setFamily(row.font_name) qfont.setPixelSize(row.font_size) diff --git a/qt/aqt/qt/__init__.py b/qt/aqt/qt/__init__.py index 631d12cf1..c60601fa8 100644 --- a/qt/aqt/qt/__init__.py +++ b/qt/aqt/qt/__init__.py @@ -7,7 +7,7 @@ import os import sys import traceback -from typing import Callable, Union +from typing import Callable, TypeVar, Union try: import PyQt6 @@ -58,3 +58,16 @@ def qconnect( ) -> None: """Helper to work around type checking not working with signal.connect(func).""" signal.connect(func) # type: ignore + + +_T = TypeVar("_T") + + +def without_qt5_compat_wrapper(cls: _T) -> _T: + """Remove Qt5 compat wrapper from Qt class, if active. + + Only needed for a few Qt APIs that deal with QVariants.""" + if fn := getattr(cls, "_without_compat_wrapper", None): + return fn() + else: + return cls diff --git a/qt/aqt/qt/qt5_compat.py b/qt/aqt/qt/qt5_compat.py index 98a054b1a..e549994b8 100644 --- a/qt/aqt/qt/qt5_compat.py +++ b/qt/aqt/qt/qt5_compat.py @@ -352,7 +352,9 @@ def _instrument_type( class QtClassProxy( type, metaclass=QtClassProxyType ): # pylint: disable=invalid-metaclass - pass + @staticmethod + def _without_compat_wrapper(): + return type setattr(module, type_name, QtClassProxy)