summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristoph Schleifenbaum <christoph.schleifenbaum@kdab.com>2014-08-25 12:29:18 +0200
committerChristoph Schleifenbaum <christoph.schleifenbaum@kdab.com>2014-08-29 07:26:29 +0200
commitfc4993be1fa7673016b6e5d81134463f163051f6 (patch)
treea6d100fc3478bd09557a67900844b4940ebd2579 /src
parente4a778d9c261b6707cd9a3c4c174d8809a1cf9d3 (diff)
QListView: Catch stack overflow on mutual scrollbar calculation.
Task-number: QTBUG-39902 Change-Id: Ie850371098070e8ce485d5cb122aa89c18d97359 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/itemviews/qlistview.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 135f89d4ac..5706be4b6d 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -1846,14 +1846,44 @@ void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step)
{
horizontalScrollBar()->setSingleStep(step.width() + spacing());
horizontalScrollBar()->setPageStep(viewport()->width());
- horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width());
+
+ // If both scroll bars are set to auto, we might end up in a situation with enough space
+ // for the actual content. But still one of the scroll bars will become enabled due to
+ // the other one using the space. The other one will become invisible in the same cycle.
+ // -> Infinite loop, QTBUG-39902
+ const bool bothScrollBarsAuto = qq->verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded &&
+ qq->horizontalScrollBarPolicy() == Qt::ScrollBarAsNeeded;
+
+ if (bothScrollBarsAuto && contentsSize.width() - qq->verticalScrollBar()->width() <= viewport()->width()
+ && contentsSize.height() - qq->horizontalScrollBar()->height() <= viewport()->height()) {
+ // break the infinite loop described above by setting the range to 0, 0.
+ // QAbstractScrollArea will then hide the scroll bar for us
+ horizontalScrollBar()->setRange(0, 0);
+ } else {
+ horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width());
+ }
}
void QCommonListViewBase::updateVerticalScrollBar(const QSize &step)
{
verticalScrollBar()->setSingleStep(step.height() + spacing());
verticalScrollBar()->setPageStep(viewport()->height());
- verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height());
+
+ // If both scroll bars are set to auto, we might end up in a situation with enough space
+ // for the actual content. But still one of the scroll bars will become enabled due to
+ // the other one using the space. The other one will become invisible in the same cycle.
+ // -> Infinite loop, QTBUG-39902
+ const bool bothScrollBarsAuto = qq->verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded &&
+ qq->horizontalScrollBarPolicy() == Qt::ScrollBarAsNeeded;
+
+ if (bothScrollBarsAuto && contentsSize.width() - qq->verticalScrollBar()->width() <= viewport()->width()
+ && contentsSize.height() - qq->horizontalScrollBar()->height() <= viewport()->height()) {
+ // break the infinite loop described above by setting the range to 0, 0.
+ // QAbstractScrollArea will then hide the scroll bar for us
+ verticalScrollBar()->setRange(0, 0);
+ } else {
+ verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height());
+ }
}
void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool /*scrollElasticBand*/)