summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-07-16 12:58:41 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-07-20 13:20:23 +0200
commita1a6e3d21b1a4fb799dfd245fed6bb6564178894 (patch)
tree502b1296f6e5973c074cd2241040892133896a09 /tests
parent3ee587f8fa4086b0cc9ba85f08c26ee646344177 (diff)
Support pt units for sizes, as documented
Declaration::lengthValue only supported 'px' sizes, but one can transform any 'pt' value into 'px' by multiplying with 1.33. Notes: this ignores display DPI, and instead follows the W3C definition of 'pt' and 'px' as absolute lengths [1]. [1] https://www.w3.org/TR/css3-values/#absolute-lengths 1pt = 1/72th of 1 inch 1px = 1/96th of 1 inch so the conversion is px = pt * (72/96). Add unit test that verifies this using QPushButton's icon-sizes property, also with changed font in preparation of adding support for 'em' and 'ex' units in a follow up commit. Task-number: QTBUG-8096 Pick-to: 6.2 Done-with: Cristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> Change-Id: I58782e7ad0e2ff9d89ed695f8a23b1e584cfed64 Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
index a4ce5ac77e..63db23f3b0 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
+++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
@@ -139,6 +139,9 @@ private slots:
void highdpiImages_data();
void highdpiImages();
+ void iconSizes_data();
+ void iconSizes();
+
private:
static QColor COLOR(const QWidget &w)
{
@@ -2337,6 +2340,38 @@ void tst_QStyleSheetStyle::placeholderColor()
QCOMPARE(le2.palette().placeholderText(), red);
}
+void tst_QStyleSheetStyle::iconSizes_data()
+{
+ QTest::addColumn<QString>("styleSheet");
+ QTest::addColumn<QFont>("font");
+ QTest::addColumn<QSize>("iconSize");
+
+ const int defaultSize = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize);
+
+ QFont smallFont;
+ smallFont.setPointSizeF(9.0);
+ QFont largeFont;
+ largeFont.setPointSizeF(24.0);
+
+ QTest::addRow("default") << QString() << QFont() << QSize(defaultSize, defaultSize);
+ QTest::addRow("pixels") << "icon-size: 50px" << QFont() << QSize(50, 50);
+ QTest::addRow("points") << "icon-size: 20pt" << QFont() << QSize(15, 15);
+ QTest::addRow("pixels with font") << "icon-size: 50px" << smallFont << QSize(50, 50);
+ QTest::addRow("points with font") << "icon-size: 20pt" << largeFont << QSize(15, 15);
+}
+
+void tst_QStyleSheetStyle::iconSizes()
+{
+ QFETCH(QString, styleSheet);
+ QFETCH(QFont, font);
+ QFETCH(QSize, iconSize);
+
+ QPushButton button;
+ button.setFont(font);
+ button.setStyleSheet(styleSheet);
+ QCOMPARE(button.iconSize(), iconSize);
+}
+
QTEST_MAIN(tst_QStyleSheetStyle)
#include "tst_qstylesheetstyle.moc"