summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-05-04 14:16:11 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-05-06 20:06:44 +0200
commite3b2b12a912361af309302a4b1fc27c2206322af (patch)
treebac865f568ee690e26a9aa1feed8c4e7c8e83560 /tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
parenta5c760a325bc4c1a3294c9533091eeae8a123a1d (diff)
QTabBar: take a style sheet's font into account when laying out tabs
If a tab has a font assigned to it through a style sheet, then take the font size into account when calculating the contents rectangle. Add a test, which hardcodes the windows style to avoid flaky behavior when e.g. macOS lays tabs out in the center. Fixes: QTBUG-92988 Pick-to: 6.1 Change-Id: Ifb0ac97db7647cc25367972737be8878e50f6040 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp')
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
index f2f9be6bb6..6c4c7d577b 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
+++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
@@ -106,6 +106,8 @@ private slots:
#endif
void background();
void tabAlignment();
+ void tabFont_data();
+ void tabFont();
void attributesList();
void minmaxSizes();
void task206238_twice();
@@ -1179,6 +1181,71 @@ void tst_QStyleSheetStyle::tabAlignment()
QVERIFY(bar->geometry().top() > 100);
}
+void tst_QStyleSheetStyle::tabFont_data()
+{
+ QTest::addColumn<int>("pixelSize");
+ QTest::addColumn<QTabWidget::TabPosition>("tabPosition");
+
+ QTest::newRow("medium, horizontal") << 24 << QTabWidget::North;
+ QTest::newRow("large, vertical") << 36 << QTabWidget::West;
+}
+
+#include <QApplication>
+
+void tst_QStyleSheetStyle::tabFont()
+{
+ QFETCH(int, pixelSize);
+ QFETCH(QTabWidget::TabPosition, tabPosition);
+ const bool vertical = tabPosition == QTabWidget::West || tabPosition == QTabWidget::East;
+
+ // macOS style centers tabs and messes up the test
+ QWindowsStyle windowsStyle;
+ QWidget topLevel;
+ topLevel.setStyle(&windowsStyle);
+ topLevel.setWindowTitle(QTest::currentTestFunction());
+ QTabWidget tabWidget;
+ tabWidget.setStyle(&windowsStyle);
+ tabWidget.addTab(new QWidget,"Tab title");
+ tabWidget.setTabPosition(tabPosition);
+ QTabWidget styledWidget;
+ styledWidget.setStyle(&windowsStyle);
+ styledWidget.setTabPosition(tabPosition);
+ styledWidget.addTab(new QWidget,"Tab title");
+
+ QTabBar *bar = tabWidget.tabBar();
+ QTabBar *styledBar = styledWidget.tabBar();
+ QVERIFY(bar && styledBar);
+ bar->setStyle(&windowsStyle);
+ styledBar->setStyle(&windowsStyle);
+
+ QBoxLayout box(vertical ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom);
+ box.addWidget(&tabWidget);
+ box.addWidget(&styledWidget);
+ topLevel.setLayout(&box);
+
+ topLevel.resize(600, 600);
+ centerOnScreen(&topLevel);
+ topLevel.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
+
+ const QRect defaultRect = bar->tabRect(0);
+ QCOMPARE(styledBar->tabRect(0), defaultRect);
+
+ QFont font;
+ font.setPointSize(pixelSize);
+ tabWidget.setFont(font);
+
+ 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));
+ const QRect rectWithStyle = styledBar->tabRect(0);
+ QCOMPARE(rectWithStyle.size(), rectWithFont.size());
+}
+
void tst_QStyleSheetStyle::attributesList()
{
const QColor blue(Qt::blue);