Prevent recursive resize events in QAbstractScrollArea

During show() of a QAbstractScrollArea we might get resize events, which
results in laying out the children of the scroll area. One of these
children are the scrollbars, and raising them to the top means creating
them, which in turn means creating all parents, including the abstract
scroll area itself. Creating the abstract scroll area means creating
a platform window, which might send synchronous resize events as a
result of creating the window, and we end up recursing.

Change-Id: I1a2813f03091d6c42e51834315835551cb2fd621
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
This commit is contained in:
Tor Arne Vestbø 2013-12-04 16:38:01 +01:00 committed by The Qt Project
parent b86426c81e
commit 1782fc1e07
2 changed files with 7 additions and 2 deletions

View File

@ -167,7 +167,7 @@ QT_BEGIN_NAMESPACE
QAbstractScrollAreaPrivate::QAbstractScrollAreaPrivate()
:hbar(0), vbar(0), vbarpolicy(Qt::ScrollBarAsNeeded), hbarpolicy(Qt::ScrollBarAsNeeded),
shownOnce(false), sizeAdjustPolicy(QAbstractScrollArea::AdjustIgnored),
shownOnce(false), inResize(false), sizeAdjustPolicy(QAbstractScrollArea::AdjustIgnored),
viewport(0), cornerWidget(0), left(0), top(0), right(0), bottom(0),
xoffset(0), yoffset(0), viewportFilter(0)
#ifdef Q_WS_WIN
@ -995,8 +995,12 @@ bool QAbstractScrollArea::event(QEvent *e)
d->viewport->setMouseTracking(hasMouseTracking());
break;
case QEvent::Resize:
if (!d->inResize) {
d->inResize = true;
d->layoutChildren();
break;
d->inResize = false;
}
break;
case QEvent::Show:
if (!d->shownOnce && d->sizeAdjustPolicy == QAbstractScrollArea::AdjustToContentsOnFirstShow) {
d->sizeHint = QSize();

View File

@ -76,6 +76,7 @@ public:
Qt::ScrollBarPolicy vbarpolicy, hbarpolicy;
bool shownOnce;
bool inResize;
mutable QSize sizeHint;
QAbstractScrollArea::SizeAdjustPolicy sizeAdjustPolicy;