Fix custom browser font not being honored

https://forums.ankiweb.net/t/on-anki-2-1-50-browser-table-font-override-is-not-respected/19259
This commit is contained in:
Damien Elmes 2022-04-21 13:28:22 +10:00
parent ef51bcefd6
commit 6f764aeda4
3 changed files with 20 additions and 3 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)