Fix font matching style bug (#2503)
This commit is contained in:
@@ -445,6 +445,7 @@ def fontMatcher(font: QFont) -> QFont:
|
||||
default Qt font matching algorithm doesn't handle well changing
|
||||
application fonts at runtime.
|
||||
"""
|
||||
font.setStyleName(None) # Make sure no font style name is set from config, see #2502
|
||||
info = QFontInfo(font)
|
||||
if (famRequest := font.family()) != (famActual := info.family()):
|
||||
logger.warning("Font mismatch: Requested '%s', but got '%s'", famRequest, famActual)
|
||||
|
||||
@@ -537,6 +537,11 @@ def testBaseCommon_fontMatcher(monkeypatch):
|
||||
nonsense = QFont("nonesense", 10)
|
||||
assert fontMatcher(nonsense) is nonsense
|
||||
|
||||
# Style is reset
|
||||
nonsense.setStyleName("blabla")
|
||||
assert nonsense.styleName() == "blabla"
|
||||
assert fontMatcher(nonsense).styleName() == ""
|
||||
|
||||
# General font
|
||||
if len(QFontDatabase.families()) > 1:
|
||||
fontOne = QFont(QFontDatabase.families()[0])
|
||||
|
||||
Reference in New Issue
Block a user