diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qscrollarea')
3 files changed, 76 insertions, 46 deletions
diff --git a/tests/auto/widgets/widgets/qscrollarea/CMakeLists.txt b/tests/auto/widgets/widgets/qscrollarea/CMakeLists.txt index 0de4565b5d..5e84614407 100644 --- a/tests/auto/widgets/widgets/qscrollarea/CMakeLists.txt +++ b/tests/auto/widgets/widgets/qscrollarea/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qscrollarea.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qscrollarea Test: ##################################################################### -qt_add_test(tst_qscrollarea +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qscrollarea LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qscrollarea SOURCES tst_qscrollarea.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/widgets/widgets/qscrollarea/qscrollarea.pro b/tests/auto/widgets/widgets/qscrollarea/qscrollarea.pro deleted file mode 100644 index bdf18a0252..0000000000 --- a/tests/auto/widgets/widgets/qscrollarea/qscrollarea.pro +++ /dev/null @@ -1,10 +0,0 @@ -############################################################ -# Project file for autotest for file qscrollarea.h -############################################################ - -CONFIG += testcase -TARGET = tst_qscrollarea -QT += widgets testlib -SOURCES += tst_qscrollarea.cpp - - diff --git a/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp b/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp index 9f08bd337b..87a623b223 100644 --- a/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp +++ b/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp @@ -1,38 +1,14 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - - -#include <QtTest/QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include <QTest> #include <qcoreapplication.h> #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() @@ -80,12 +57,12 @@ void tst_QScrollArea::getSetCheck() class WidgetWithMicroFocus : public QWidget { public: - WidgetWithMicroFocus(QWidget *parent = 0) : QWidget(parent) + WidgetWithMicroFocus(QWidget *parent = nullptr) : QWidget(parent) { setBackgroundRole(QPalette::Dark); } protected: - QVariant inputMethodQuery(Qt::InputMethodQuery query) const + QVariant inputMethodQuery(Qt::InputMethodQuery query) const override { if (query == Qt::ImCursorRectangle) return QRect(width() / 2, height() / 2, 5, 5); @@ -120,7 +97,7 @@ class HFWWidget : public QWidget { public: HFWWidget(); - int heightForWidth(int w) const; + int heightForWidth(int w) const override; }; HFWWidget::HFWWidget() @@ -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" |