summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp')
-rw-r--r--tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp87
1 files changed, 60 insertions, 27 deletions
diff --git a/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp b/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp
index 8a9200f406..87a623b223 100644
--- a/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp
+++ b/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -33,6 +8,7 @@
#include <qdebug.h>
#include <qscrollarea.h>
#include <qlayout.h>
+#include <qscrollbar.h>
class tst_QScrollArea : public QObject
{
@@ -46,6 +22,7 @@ private slots:
void getSetCheck();
void ensureMicroFocusVisible_Task_167838();
void checkHFW_Task_197736();
+ void stableHeightForWidth();
};
tst_QScrollArea::tst_QScrollArea()
@@ -165,5 +142,61 @@ void tst_QScrollArea::checkHFW_Task_197736()
QCOMPARE(w->height(), 200);
}
+
+/*
+ If the scroll area rides the size where, due to the height-for-width
+ implementation of the widget, the vertical scrollbar is needed only
+ if the vertical scrollbar is visible, then we don't want it to flip
+ back and forth, but rather constrain the width of the widget.
+ See QTBUG-92958.
+*/
+void tst_QScrollArea::stableHeightForWidth()
+{
+ struct HeightForWidthWidget : public QWidget
+ {
+ HeightForWidthWidget()
+ {
+ QSizePolicy policy = sizePolicy();
+ policy.setHeightForWidth(true);
+ setSizePolicy(policy);
+ }
+ // Aspect ratio 1:1
+ int heightForWidth(int width) const override { return width; }
+ };
+
+ class HeightForWidthArea : public QScrollArea
+ {
+ public:
+ HeightForWidthArea()
+ {
+ this->verticalScrollBar()->installEventFilter(this);
+ }
+ protected:
+ bool eventFilter(QObject *obj, QEvent *e) override
+ {
+ if (obj == verticalScrollBar() && e->type() == QEvent::Hide)
+ ++m_hideCount;
+ return QScrollArea::eventFilter(obj,e);
+ }
+ public:
+ int m_hideCount = 0;
+ };
+
+ HeightForWidthArea area;
+ HeightForWidthWidget equalWHWidget;
+ area.setWidget(&equalWHWidget);
+ area.setWidgetResizable(true);
+ // at this size, the widget wants to be 501 pixels high,
+ // requiring a vertical scrollbar in a 499 pixel high area.
+ // but the width resulting from showing the scrollbar would
+ // be less than 499, so no scrollbars would be needed anymore.
+ area.resize(501, 499);
+ area.show();
+ QTest::qWait(500);
+ // if the scrollbar got hidden more than once, then the layout
+ // isn't stable.
+ QVERIFY(area.m_hideCount <= 1);
+}
+
QTEST_MAIN(tst_QScrollArea)
#include "tst_qscrollarea.moc"