Utils: Don't use fixed font sizes for Markdown headings

Otherwise the headings won't follow the widgets base font size
changes.

Change-Id: I8301341570ae46b82d53635bc74f37d418a8feea
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-10-30 10:00:05 +01:00
parent b7471f58eb
commit 91c6964f7b

View File

@@ -434,11 +434,15 @@ void MarkdownBrowser::setMarkdown(const QString &markdown)
cursor.setPosition(fragment.position());
cursor.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);
if (blockFormat.hasProperty(QTextFormat::HeadingLevel)) {
// We don't use font size adjustment for headings
charFormat.clearProperty(QTextFormat::FontSizeAdjustment);
// Change font size adjustment to resemble the heading font size
// (We want the font size to be relative to the default font size,
// otherwise the heading size won't respect the font scale factor)
charFormat.setProperty(
QTextFormat::FontSizeAdjustment,
headingFont.pointSizeF() / document()->defaultFont().pointSizeF());
charFormat.setFontCapitalization(headingFont.capitalization());
charFormat.setFontFamilies(headingFont.families());
charFormat.setFontPointSize(headingFont.pointSizeF());
charFormat.setFontWeight(headingFont.weight());
charFormat.setForeground(color(headingTf));
} else if (charFormat.isAnchor()) {