Force repaint of litehtml help viewer when font changes

Trigger refresh_styles() and parse_styles() on font change.

Change-Id: I3ea667b2d9fb382681ffad2279823500e9e20491
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2021-01-19 13:04:34 +01:00
parent 291f46386f
commit 0fe8089214
2 changed files with 12 additions and 4 deletions

View File

@@ -1235,6 +1235,12 @@ void DocumentContainer::setDefaultFont(const QFont &font)
{
d->m_defaultFont = font;
d->m_defaultFontFamilyName = d->m_defaultFont.family().toUtf8();
// Since font family name and size are read only once, when parsing html,
// we need to trigger the reparse of this info.
if (d->m_document && d->m_document->root()) {
d->m_document->root()->refresh_styles();
d->m_document->root()->parse_styles();
}
}
QFont DocumentContainer::defaultFont() const

View File

@@ -464,7 +464,7 @@ bool QLiteHtmlWidget::findText(const QString &text,
.findText(text, flags, incremental, wrapped, &success, &oldSelection, &newSelection);
// scroll to search result position and/or redraw as necessary
QRect newSelectionCombined;
for (const QRect &r : newSelection)
for (const QRect &r : qAsConst(newSelection))
newSelectionCombined = newSelectionCombined.united(r);
QScrollBar *vBar = verticalScrollBar();
const int top = newSelectionCombined.top();
@@ -475,7 +475,7 @@ bool QLiteHtmlWidget::findText(const QString &text,
vBar->setValue(bottom);
} else {
viewport()->update(fromVirtual(newSelectionCombined.translated(-scrollPosition())));
for (const QRect &r : oldSelection)
for (const QRect &r : qAsConst(oldSelection))
viewport()->update(fromVirtual(r.translated(-scrollPosition())));
}
return success;
@@ -483,8 +483,10 @@ bool QLiteHtmlWidget::findText(const QString &text,
void QLiteHtmlWidget::setDefaultFont(const QFont &font)
{
d->documentContainer.setDefaultFont(font);
render();
withFixedTextPosition([this, &font] {
d->documentContainer.setDefaultFont(font);
render();
});
}
QFont QLiteHtmlWidget::defaultFont() const