diff options
author | Eike Ziller <eike.ziller@qt.io> | 2019-09-26 11:28:04 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2019-10-01 11:32:41 +0000 |
commit | 123aa77c4914b8b6088740b7f3cc6f98ae6d644e (patch) | |
tree | 750e2dcfb5a9e0ff904abaf80664c3619e50db67 /src/plugins/help | |
parent | c2e6dd6958ce344dfc63ecb716cb4e594537dd49 (diff) |
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 <hjk@qt.io>
Diffstat (limited to 'src/plugins/help')
-rw-r--r-- | src/plugins/help/qlitehtml/qlitehtmlwidget.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
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) |