summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/styles
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/styles')
-rw-r--r--tests/auto/widgets/styles/CMakeLists.txt7
-rw-r--r--tests/auto/widgets/styles/qmacstyle/CMakeLists.txt11
-rw-r--r--tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp29
-rw-r--r--tests/auto/widgets/styles/qstyle/CMakeLists.txt11
-rw-r--r--tests/auto/widgets/styles/qstyle/tst_qstyle.cpp139
-rw-r--r--tests/auto/widgets/styles/qstyleoption/CMakeLists.txt14
-rw-r--r--tests/auto/widgets/styles/qstyleoption/tst_qstyleoption.cpp29
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/CMakeLists.txt38
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp220
9 files changed, 320 insertions, 178 deletions
diff --git a/tests/auto/widgets/styles/CMakeLists.txt b/tests/auto/widgets/styles/CMakeLists.txt
index b1c9d1fce3..a957dfd373 100644
--- a/tests/auto/widgets/styles/CMakeLists.txt
+++ b/tests/auto/widgets/styles/CMakeLists.txt
@@ -1,9 +1,12 @@
-# Generated from styles.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
if(APPLE)
add_subdirectory(qmacstyle)
endif()
-add_subdirectory(qstyle)
+if(QT_FEATURE_private_tests)
+ add_subdirectory(qstyle)
+endif()
add_subdirectory(qstyleoption)
if(QT_FEATURE_private_tests AND NOT ANDROID AND NOT QNX AND NOT UIKIT)
add_subdirectory(qstylesheetstyle)
diff --git a/tests/auto/widgets/styles/qmacstyle/CMakeLists.txt b/tests/auto/widgets/styles/qmacstyle/CMakeLists.txt
index fcff4fcc21..861a327418 100644
--- a/tests/auto/widgets/styles/qmacstyle/CMakeLists.txt
+++ b/tests/auto/widgets/styles/qmacstyle/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qmacstyle.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmacstyle Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmacstyle LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qmacstyle
SOURCES
tst_qmacstyle.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::WidgetsPrivate
)
diff --git a/tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp b/tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp
index fd784f9ced..9cfd50bc08 100644
--- a/tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp
+++ b/tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.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>
diff --git a/tests/auto/widgets/styles/qstyle/CMakeLists.txt b/tests/auto/widgets/styles/qstyle/CMakeLists.txt
index c3b7b44e28..2c617ebe49 100644
--- a/tests/auto/widgets/styles/qstyle/CMakeLists.txt
+++ b/tests/auto/widgets/styles/qstyle/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qstyle.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qstyle Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qstyle LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qstyle
SOURCES
tst_qstyle.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::TestPrivate
Qt::Widgets
diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
index 0578d5ce70..95e24da21d 100644
--- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
+++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 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) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -92,6 +67,11 @@ private slots:
void testProxyCalled();
void testStyleOptionInit();
+
+ void sliderPositionFromValue_data();
+ void sliderPositionFromValue();
+ void sliderValueFromPosition_data();
+ void sliderValueFromPosition();
private:
bool testAllFunctions(QStyle *);
bool testScrollBarSubControls(const QStyle *style);
@@ -653,7 +633,7 @@ void tst_QStyle::testStyleOptionInit()
QStringList keys = QStyleFactory::keys();
keys.prepend(QString()); // QCommonStyle marker
- for (const QString &key : qAsConst(keys)) {
+ for (const QString &key : std::as_const(keys)) {
QStyle* style = key.isEmpty() ? new QCommonStyle : QStyleFactory::create(key);
TestStyleOptionInitProxy testStyle;
testStyle.setBaseStyle(style);
@@ -662,5 +642,108 @@ void tst_QStyle::testStyleOptionInit()
}
}
+void tst_QStyle::sliderPositionFromValue_data()
+{
+ QTest::addColumn<int>("min");
+ QTest::addColumn<int>("max");
+ QTest::addColumn<int>("value");
+ QTest::addColumn<int>("span");
+ QTest::addColumn<bool>("upsideDown");
+ QTest::addColumn<int>("position");
+
+ QTest::addRow("no span") << 12 << 56 << 34 << 0 << false << 0;
+ QTest::addRow("no span inverse") << 12 << 56 << 34 << 0 << true << 0;
+
+ QTest::addRow("value too small") << 34 << 56 << 12 << 2000 << false << 0;
+ QTest::addRow("value too small inverse") << 34 << 56 << 12 << 2000 << true << 2000;
+
+ QTest::addRow("no-range") << 12 << 12 << 12 << 2000 << false << 0;
+ QTest::addRow("no-range-inverse") << 12 << 12 << 12 << 2000 << true << 0;
+
+ QTest::addRow("close-to-max") << 12 << 34 << 33 << 2000 << false << 1909;
+ QTest::addRow("at-max") << 12 << 34 << 34 << 2000 << false << 2000;
+ QTest::addRow("value too large") << 12 << 34 << 35 << 2000 << false << 2000;
+ QTest::addRow("close-to-max-inverse") << 12 << 34 << 33 << 2000 << true << 91;
+ QTest::addRow("at-max-inverse") << 12 << 34 << 34 << 2000 << true << 0;
+ QTest::addRow("value too large-inverse") << 12 << 34 << 35 << 2000 << true << 0;
+
+ QTest::addRow("big-range") << 100000 << 700000 << 250000 << 2000 << false << 500;
+ QTest::addRow("big-range-inverse") << 100000 << 700000 << 250000 << 2000 << true << 1500;
+
+ QTest::addRow("across-zero") << -1000 << 1000 << -500 << 100 << false << 25;
+ QTest::addRow("across-zero-inverse") << -1000 << 1000 << -500 << 100 << true << 75;
+
+ QTest::addRow("span>range") << 0 << 100 << 60 << 2000 << false << 1200;
+ QTest::addRow("span>range-inverse") << 0 << 100 << 60 << 2000 << true << 800;
+
+ QTest::addRow("overflow1 (QTBUG-101581)") << -1 << INT_MAX << 235 << 891 << false << 0;
+ QTest::addRow("overflow2") << INT_MIN << INT_MAX << 10 << 100 << false << 50;
+ QTest::addRow("overflow2-inverse") << INT_MIN << INT_MAX << 10 << 100 << true << 49;
+ QTest::addRow("overflow3") << INT_MIN << INT_MAX << -10 << 100 << false << 49;
+ QTest::addRow("overflow3-inverse") << INT_MIN << INT_MAX << -10 << 100 << true << 50;
+}
+
+void tst_QStyle::sliderPositionFromValue()
+{
+ QFETCH(int, min);
+ QFETCH(int, max);
+ QFETCH(int, value);
+ QFETCH(int, span);
+ QFETCH(bool, upsideDown);
+ QFETCH(int, position);
+
+ QCOMPARE(QStyle::sliderPositionFromValue(min, max, value, span, upsideDown), position);
+}
+
+void tst_QStyle::sliderValueFromPosition_data()
+{
+ QTest::addColumn<int>("min");
+ QTest::addColumn<int>("max");
+ QTest::addColumn<int>("position");
+ QTest::addColumn<int>("span");
+ QTest::addColumn<bool>("upsideDown");
+ QTest::addColumn<int>("value");
+
+ QTest::addRow("position zero") << 0 << 100 << 0 << 2000 << false << 0;
+ QTest::addRow("position zero inverse") << 0 << 100 << 0 << 2000 << true << 100;
+
+ QTest::addRow("span zero") << 0 << 100 << 1200 << 0 << false << 0;
+ QTest::addRow("span zero inverse") << 0 << 100 << 1200 << 0 << true << 100;
+
+ QTest::addRow("position > span") << -300 << -200 << 2 << 1 << false << -200;
+ QTest::addRow("position > span inverse") << -300 << -200 << 2 << 1 << true << -300;
+
+ QTest::addRow("large") << 0 << 100 << 1200 << 2000 << false << 60;
+ QTest::addRow("large-inverse") << 0 << 100 << 1200 << 2000 << true << 40;
+
+ QTest::addRow("normal") << 0 << 100 << 12 << 20 << false << 60;
+ QTest::addRow("inverse") << 0 << 100 << 12 << 20 << true << 40;
+
+ QTest::addRow("overflow1") << -1 << INT_MAX << 10 << 10 << false << INT_MAX;
+ QTest::addRow("overflow1-inverse") << -1 << INT_MAX << 10 << 10 << true << -1;
+ QTest::addRow("overflow2") << INT_MIN << INT_MAX << 5 << 10 << false << 0;
+ QTest::addRow("overflow2-inverse") << INT_MIN << INT_MAX << 5 << 10 << true << -1;
+ QTest::addRow("overflow3") << INT_MIN << 0 << 0 << 10 << false << INT_MIN;
+ QTest::addRow("overflow3-inverse") << INT_MIN << 0 << 0 << 10 << true << 0;
+
+ QTest::addRow("overflow4") << 0 << INT_MAX << INT_MAX/2-6 << INT_MAX/2-5 << false << INT_MAX-2;
+ QTest::addRow("overflow4-inverse") << 0 << INT_MAX << INT_MAX/2-6 << INT_MAX/2-5 << true << 2;
+
+ QTest::addRow("overflow5") << 0 << 4 << INT_MAX/4 << INT_MAX << false << 1;
+ QTest::addRow("overflow5-inverse") << 0 << 4 << INT_MAX/4 << INT_MAX << true << 3;
+}
+
+void tst_QStyle::sliderValueFromPosition()
+{
+ QFETCH(int, min);
+ QFETCH(int, max);
+ QFETCH(int, position);
+ QFETCH(int, span);
+ QFETCH(bool, upsideDown);
+ QFETCH(int, value);
+
+ QCOMPARE(QStyle::sliderValueFromPosition(min, max, position, span, upsideDown), value);
+}
+
QTEST_MAIN(tst_QStyle)
#include "tst_qstyle.moc"
diff --git a/tests/auto/widgets/styles/qstyleoption/CMakeLists.txt b/tests/auto/widgets/styles/qstyleoption/CMakeLists.txt
index 05853dfb62..e0a4cc38e2 100644
--- a/tests/auto/widgets/styles/qstyleoption/CMakeLists.txt
+++ b/tests/auto/widgets/styles/qstyleoption/CMakeLists.txt
@@ -1,16 +1,20 @@
-# Generated from qstyleoption.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qstyleoption Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qstyleoption LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qstyleoption
SOURCES
tst_qstyleoption.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::Widgets
)
-
-#### Keys ignored in scope 1:.:.:qstyleoption.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/auto/widgets/styles/qstyleoption/tst_qstyleoption.cpp b/tests/auto/widgets/styles/qstyleoption/tst_qstyleoption.cpp
index a08b251c35..f173c9a8df 100644
--- a/tests/auto/widgets/styles/qstyleoption/tst_qstyleoption.cpp
+++ b/tests/auto/widgets/styles/qstyleoption/tst_qstyleoption.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>
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/CMakeLists.txt b/tests/auto/widgets/styles/qstylesheetstyle/CMakeLists.txt
index bf4e52862c..6543ec9961 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/CMakeLists.txt
+++ b/tests/auto/widgets/styles/qstylesheetstyle/CMakeLists.txt
@@ -1,37 +1,33 @@
-# Generated from qstylesheetstyle.pro.
-
-if(NOT QT_FEATURE_private_tests)
- return()
-endif()
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qstylesheetstyle Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qstylesheetstyle LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+# Resources:
+set(resources_resource_files
+ "images/testimage.png"
+ "images/testimage@2x.png"
+)
+
qt_internal_add_test(tst_qstylesheetstyle
SOURCES
tst_qstylesheetstyle.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
Qt::TestPrivate
Qt::Widgets
Qt::WidgetsPrivate
+ TESTDATA ${resources_resource_files}
+ BUILTIN_TESTDATA
)
-# Resources:
-set(resources_resource_files
- "images/testimage.png"
- "images/testimage@2x.png"
-)
-
-qt_internal_add_resource(tst_qstylesheetstyle "resources"
- PREFIX
- "/"
- FILES
- ${resources_resource_files}
-)
-
-
-#### Keys ignored in scope 1:.:.:qstylesheetstyle.pro:<TRUE>:
# _REQUIREMENTS = "qtConfig(private_tests)"
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
index 492b206019..a9a1817b8a 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
+++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 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) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
@@ -63,6 +38,8 @@
#include <private/qstylesheetstyle_p.h>
#include <private/qhighdpiscaling_p.h>
#include <QtTest/private/qtesthelpers_p.h>
+#include <qpa/qplatformtheme.h>
+#include <QtWidgets/private/qapplication_p.h>
using namespace QTestPrivate;
@@ -117,6 +94,7 @@ private slots:
void proxyStyle();
void dialogButtonBox();
void emptyStyleSheet();
+ void toolTip_data();
void toolTip();
void embeddedFonts();
void opaquePaintEvent_data();
@@ -129,6 +107,7 @@ private slots:
void QTBUG36933_brokenPseudoClassLookup();
void styleSheetChangeBeforePolish();
void placeholderColor();
+ void accent();
void enumPropertySelector_data();
void enumPropertySelector();
//at the end because it mess with the style.
@@ -143,6 +122,8 @@ private slots:
void iconSizes_data();
void iconSizes();
+ void inheritWidgetPalette_data();
+ void inheritWidgetPalette();
private:
static QColor COLOR(const QWidget &w)
@@ -984,7 +965,7 @@ void tst_QStyleSheetStyle::focusColors()
// ten pixels of the right color requires quite a many characters, as the
// majority of the pixels will have slightly different colors due to the
// anti-aliasing effect.
-#if !defined(Q_OS_WIN32) && !(defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(Q_CC_INTEL))
+#if !defined(Q_OS_WIN32) && !(defined(Q_OS_LINUX) && defined(Q_CC_GNU))
QSKIP("This is a fragile test which fails on many esoteric platforms because of focus problems"
" (for example, QTBUG-33959)."
"That doesn't mean that the feature doesn't work in practice.");
@@ -999,7 +980,6 @@ void tst_QStyleSheetStyle::focusColors()
centerOnScreen(&frame);
frame.show();
- QApplication::setActiveWindow(&frame);
QVERIFY(QTest::qWaitForWindowActive(&frame));
for (QWidget *widget : frame.widgets()) {
@@ -1045,7 +1025,6 @@ void tst_QStyleSheetStyle::hoverColors()
QCursor::setPos(frame.geometry().topLeft() - QPoint(100, 0));
frame.show();
- QApplication::setActiveWindow(&frame);
QVERIFY(QTest::qWaitForWindowActive(&frame));
QWindow *frameWindow = frame.windowHandle();
@@ -1220,20 +1199,31 @@ void tst_QStyleSheetStyle::tabAlignment()
void tst_QStyleSheetStyle::tabFont_data()
{
- QTest::addColumn<int>("pixelSize");
+ QTest::addColumn<QFont>("tabFont");
QTest::addColumn<QTabWidget::TabPosition>("tabPosition");
+ QTest::addColumn<bool>("closable");
- QTest::newRow("medium, horizontal") << 24 << QTabWidget::North;
- QTest::newRow("large, vertical") << 36 << QTabWidget::West;
-}
+ QFont medium;
+ medium.setPixelSize(24);
+ QFont large;
+ large.setPixelSize(36);
+ QFont bold;
+ bold.setBold(true);
-#include <QApplication>
+ QTest::newRow("medium, horizontal") << medium << QTabWidget::North << false;
+ QTest::newRow("large, vertical") << large << QTabWidget::West << false;
+ QTest::newRow("bold, horizontal, closable") << bold << QTabWidget::North << true;
+ QTest::newRow("bold, vertical, closable") << bold << QTabWidget::West << true;
+}
void tst_QStyleSheetStyle::tabFont()
{
- QFETCH(int, pixelSize);
+ QFETCH(QFont, tabFont);
QFETCH(QTabWidget::TabPosition, tabPosition);
+ QFETCH(bool, closable);
const bool vertical = tabPosition == QTabWidget::West || tabPosition == QTabWidget::East;
+ const QString tab0Text("Tab title");
+ const QString tab1Text("Very Long Tab title");
// macOS style centers tabs and messes up the test
QWindowsStyle windowsStyle;
@@ -1242,18 +1232,22 @@ void tst_QStyleSheetStyle::tabFont()
topLevel.setWindowTitle(QTest::currentTestFunction());
QTabWidget tabWidget;
tabWidget.setStyle(&windowsStyle);
- tabWidget.addTab(new QWidget,"Tab title");
tabWidget.setTabPosition(tabPosition);
+ tabWidget.addTab(new QWidget, tab0Text);
+ tabWidget.addTab(new QWidget, tab1Text);
QTabWidget styledWidget;
styledWidget.setStyle(&windowsStyle);
styledWidget.setTabPosition(tabPosition);
- styledWidget.addTab(new QWidget,"Tab title");
+ styledWidget.addTab(new QWidget, tab0Text);
+ styledWidget.addTab(new QWidget, tab1Text);
QTabBar *bar = tabWidget.tabBar();
QTabBar *styledBar = styledWidget.tabBar();
QVERIFY(bar && styledBar);
bar->setStyle(&windowsStyle);
+ bar->setTabsClosable(closable);
styledBar->setStyle(&windowsStyle);
+ styledBar->setTabsClosable(closable);
QBoxLayout box(vertical ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom);
box.addWidget(&tabWidget);
@@ -1265,22 +1259,36 @@ void tst_QStyleSheetStyle::tabFont()
topLevel.show();
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
+ const QFont defaultFont = tabWidget.font();
+ if (QFontMetrics(defaultFont).size(Qt::TextShowMnemonic, tab0Text).width() >=
+ QFontMetrics(tabFont).size(Qt::TextShowMnemonic, tab0Text).width()) {
+ QSKIP("The used font is not larger when bold");
+ }
+
const QRect defaultRect = bar->tabRect(0);
QCOMPARE(styledBar->tabRect(0), defaultRect);
- QFont font;
- font.setPointSize(pixelSize);
- tabWidget.setFont(font);
-
+ tabWidget.setFont(tabFont);
const QRect rectWithFont = bar->tabRect(0);
if (vertical)
QVERIFY(rectWithFont.height() > defaultRect.height());
else
QVERIFY(rectWithFont.width() > defaultRect.width());
- styledWidget.setStyleSheet(QString("QTabBar { font-size: %1pt; }").arg(pixelSize));
+ QString styleSheet = "QTabBar::tab:first {";
+ if (tabFont.pixelSize() != -1)
+ styleSheet += QString(" font-size: %1px;").arg(tabFont.pixelSize());
+ if (tabFont.bold())
+ styleSheet += " font-weight: bold;";
+ styleSheet += "}";
+
+ styledWidget.setStyleSheet(styleSheet);
const QRect rectWithStyle = styledBar->tabRect(0);
- QCOMPARE(rectWithStyle.size(), rectWithFont.size());
+
+ if (vertical)
+ QCOMPARE(rectWithStyle.height(), rectWithFont.height());
+ else
+ QCOMPARE(rectWithStyle.width(), rectWithFont.width());
}
void tst_QStyleSheetStyle::attributesList()
@@ -1649,19 +1657,32 @@ private:
const QString m_oldStyleName;
};
+void tst_QStyleSheetStyle::toolTip_data()
+{
+ QTest::addColumn<QString>("style");
+
+ QTest::newRow("fusion") << QString("Fusion");
+#ifdef Q_OS_WINDOWS
+ QTest::newRow("windowsvista") << QString("WindowsVista");
+#endif
+}
+
void tst_QStyleSheetStyle::toolTip()
{
+ QFETCH(QString, style);
+
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
QSKIP("Wayland: This fails. Figure out why.");
- qApp->setStyleSheet(QString());
QWidget w;
w.resize(m_testSize);
w.setWindowTitle(QTest::currentTestFunction());
+
// Use "Fusion" to prevent the Vista style from clobbering the tooltip palette in polish().
- QStyle *fusionStyle = QStyleFactory::create(QLatin1String("Fusion"));
- QVERIFY(fusionStyle);
- ApplicationStyleSetter as(fusionStyle);
+ QStyle *appStyle = QStyleFactory::create(style);
+ QVERIFY(appStyle);
+ ApplicationStyleSetter as(appStyle);
+
QHBoxLayout layout(&w);
w.setLayout(&layout);
@@ -1689,37 +1710,65 @@ void tst_QStyleSheetStyle::toolTip()
wid4->setToolTip("this is wid4");
wid4->setObjectName("wid4");
+ QWidget *wid5 = new QPushButton("wid5", &w);
+ layout.addWidget(wid5);
+ wid5->setStyleSheet("QToolTip { background: #ff0; color: #f00 }");
+ wid5->setToolTip("this is wid5");
+ wid5->setObjectName("wid5");
+
centerOnScreen(&w);
w.show();
- QApplication::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
- const QColor normalToolTip = QToolTip::palette().color(QPalette::Inactive, QPalette::ToolTipBase);
+ QColor normalToolTipBgColor = QToolTip::palette().color(QPalette::Inactive, QPalette::ToolTipBase);
+
+#ifdef Q_OS_MACOS
+ // macOS uses tool tip text color set in label palette
+ const QPalette *labelPalette = QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::LabelPalette);
+ QColor normalToolTipFgColor = labelPalette->color(QPalette::Inactive, QPalette::ToolTipText);
+#else
+ QColor normalToolTipFgColor = QToolTip::palette().color(QPalette::Inactive, QPalette::ToolTipText);
+#endif
+
// Tooltip on the widget without stylesheet, then to other widget,
// including one without stylesheet (the tooltip will be reused,
// but its color must change)
- const QWidgetList widgets{wid4, wid1, wid2, wid3, wid4};
- const QList<QColor> colors { normalToolTip, QColor("#ae2"), QColor("#f81"), QColor("#0b8"),
- normalToolTip };
+ const QWidgetList widgets{wid4, wid1, wid2, wid3, wid4, wid5};
+ const QList<QColor> bgcolors { normalToolTipBgColor, QColor("#ae2"), QColor("#f81"),
+ QColor("#0b8"), normalToolTipBgColor, QColor("#ff0")};
+ const QList<QColor> fgcolors { normalToolTipFgColor, normalToolTipFgColor, normalToolTipFgColor,
+ normalToolTipFgColor, normalToolTipFgColor, QColor("#f00")};
QWidgetList topLevels;
- for (int i = 0; i < widgets.count() ; ++i) {
+ for (int i = 0; i < widgets.size() ; ++i) {
QWidget *wid = widgets.at(i);
- QColor col = colors.at(i);
+ QColor bgColor = bgcolors.at(i);
+ QColor fgColor = fgcolors.at(i);
QToolTip::showText( QPoint(0,0) , "This is " + wid->objectName(), wid);
topLevels = QApplication::topLevelWidgets();
QWidget *tooltip = nullptr;
- for (QWidget *widget : qAsConst(topLevels)) {
+ for (QWidget *widget : std::as_const(topLevels)) {
if (widget->inherits("QTipLabel")) {
tooltip = widget;
break;
}
}
+
QVERIFY(tooltip);
QTRY_VERIFY(tooltip->isVisible()); // Wait until Roll-Effect is finished (Windows Vista)
- QCOMPARE(tooltip->palette().color(tooltip->backgroundRole()), col);
+
+#ifdef Q_OS_WINDOWS
+ // If tooltip palette contains empty resolve mask, validate with inherited palette
+ if (!tooltip->palette().resolveMask()) {
+ bgColor = w.palette().color(tooltip->backgroundRole());
+ fgColor = w.palette().color(tooltip->foregroundRole());
+ }
+#endif
+
+ QCOMPARE(tooltip->palette().color(tooltip->backgroundRole()), bgColor);
+ QCOMPARE(tooltip->palette().color(tooltip->foregroundRole()), fgColor);
}
QToolTip::showText( QPoint(0,0) , "This is " + wid3->objectName(), wid3);
@@ -1727,7 +1776,7 @@ void tst_QStyleSheetStyle::toolTip()
delete wid3; //should not crash;
QTest::qWait(10);
topLevels = QApplication::topLevelWidgets();
- for (QWidget *widget : qAsConst(topLevels))
+ for (QWidget *widget : std::as_const(topLevels))
widget->update(); //should not crash either
}
@@ -1837,7 +1886,6 @@ void tst_QStyleSheetStyle::complexWidgetFocus()
centerOnScreen(&frame);
frame.show();
- QApplication::setActiveWindow(&frame);
QVERIFY(QTest::qWaitForWindowActive(&frame));
for (QWidget *widget : widgets) {
widget->setFocus();
@@ -1926,7 +1974,6 @@ void tst_QStyleSheetStyle::task232085_spinBoxLineEditBg()
centerOnScreen(&frame);
frame.show();
- QApplication::setActiveWindow(&frame);
spinbox->setFocus();
QVERIFY(QTest::qWaitForWindowActive(&frame));
@@ -2062,7 +2109,6 @@ void tst_QStyleSheetStyle::QTBUG36933_brokenPseudoClassLookup()
QVERIFY(QTest::qWaitForWindowExposed(&widget));
widget.activateWindow();
- QApplication::setActiveWindow(&widget);
QVERIFY(QTest::qWaitForWindowActive(&widget));
QHeaderView *verticalHeader = widget.verticalHeader();
@@ -2335,11 +2381,32 @@ void tst_QStyleSheetStyle::placeholderColor()
QLineEdit le2;
le2.setEnabled(false);
le1.ensurePolished();
- QCOMPARE(le1.palette().placeholderText(), red);
+ QColor phColor = le1.palette().placeholderText().color();
+ QCOMPARE(phColor.rgb(), red.rgb());
+ QVERIFY(phColor.alpha() < red.alpha());
+
le2.ensurePolished();
- QCOMPARE(le2.palette().placeholderText(), red);
+ phColor = le2.palette().placeholderText().color();
+ QCOMPARE(phColor.rgb(), red.rgb());
+ QVERIFY(phColor.alpha() < red.alpha());
+
le2.setEnabled(true);
- QCOMPARE(le2.palette().placeholderText(), red);
+ phColor = le2.palette().placeholderText().color();
+ QCOMPARE(phColor.rgb(), red.rgb());
+ QVERIFY(phColor.alpha() < red.alpha());
+
+ const char *phSpec = "#aabbccdd";
+ le1.setStyleSheet(QString("QLineEdit { placeholder-text-color: %1; }").arg(phSpec));
+ QCOMPARE(le1.palette().placeholderText().color(), QColor(phSpec));
+}
+
+void tst_QStyleSheetStyle::accent()
+{
+ QLineEdit lineEdit;
+ const QColor universe(42, 42, 42);
+ lineEdit.setStyleSheet(QString("QLineEdit { accent-color: %1; }").arg(universe.name()));
+ lineEdit.ensurePolished();
+ QCOMPARE(lineEdit.palette().accent().color(), universe);
}
void tst_QStyleSheetStyle::enumPropertySelector_data()
@@ -2436,6 +2503,31 @@ void tst_QStyleSheetStyle::iconSizes()
QCOMPARE(button.iconSize(), iconSize);
}
+void tst_QStyleSheetStyle::inheritWidgetPalette_data()
+{
+ QTest::addColumn<const QString>("styleSheet");
+ QTest::addColumn<const QColor>("phColorPalette");
+
+ QTest::addRow("blueAndGreen") << "QLineEdit {color: rgb(0,0,255);}" << QColor(Qt::green);
+ QTest::addRow("emptyStyleSheet") << QString() << QColor(Qt::green);
+
+}
+
+void tst_QStyleSheetStyle::inheritWidgetPalette()
+{
+ QFETCH(const QString, styleSheet);
+ QFETCH(const QColor, phColorPalette);
+
+ QLineEdit edit;
+ QPalette palette = edit.palette();
+ palette.setBrush(QPalette::PlaceholderText, phColorPalette);
+ edit.setPalette(palette);
+ edit.setStyleSheet(styleSheet);
+ const QColor phColor = edit.palette().placeholderText().color();
+
+ QCOMPARE(phColor, phColorPalette);
+}
+
QTEST_MAIN(tst_QStyleSheetStyle)
#include "tst_qstylesheetstyle.moc"