From 123aa77c4914b8b6088740b7f3cc6f98ae6d644e Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 26 Sep 2019 11:28:04 +0200 Subject: Help/litehtml: Guard against out-of-bounds scroll values If we set the value of the scrollbar to an invalid value, nothing gets repainted, so we need to take the branch that calls update explicitly in that case. Change-Id: I700c690119b1ee2fe8b88d77c29e00f329810448 Reviewed-by: hjk --- src/plugins/help/qlitehtml/qlitehtmlwidget.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/plugins/help') diff --git a/src/plugins/help/qlitehtml/qlitehtmlwidget.cpp b/src/plugins/help/qlitehtml/qlitehtmlwidget.cpp index 6692d56ffd..db8c16d5ac 100644 --- a/src/plugins/help/qlitehtml/qlitehtmlwidget.cpp +++ b/src/plugins/help/qlitehtml/qlitehtmlwidget.cpp @@ -461,13 +461,13 @@ bool QLiteHtmlWidget::findText(const QString &text, QRect newSelectionCombined; for (const QRect &r : newSelection) newSelectionCombined = newSelectionCombined.united(r); - if (success && verticalScrollBar()->value() > newSelectionCombined.top()) { - verticalScrollBar()->setValue(newSelectionCombined.top()); - } else if (success - && verticalScrollBar()->value() + toVirtual(viewport()->size()).height() - < newSelectionCombined.bottom()) { - verticalScrollBar()->setValue(newSelectionCombined.bottom() - - toVirtual(viewport()->size()).height()); + QScrollBar *vBar = verticalScrollBar(); + const int top = newSelectionCombined.top(); + const int bottom = newSelectionCombined.bottom() - toVirtual(viewport()->size()).height(); + if (success && top < vBar->value() && vBar->minimum() <= top) { + vBar->setValue(top); + } else if (success && vBar->value() < bottom && bottom <= vBar->maximum()) { + vBar->setValue(bottom); } else { viewport()->update(fromVirtual(newSelectionCombined.translated(-scrollPosition()))); for (const QRect &r : oldSelection) -- cgit v1.2.3