summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChunLin Wang <wangchunlin@uniontech.com>2021-01-11 13:14:43 +0800
committerChunLin Wang <wangchunlin@uniontech.com>2021-01-15 14:38:35 +0800
commitdafd26acbe7b08f5ddfe60432fe0e49422ac085c (patch)
tree2cc1d0a61ea78e13452d2999289725bfa7956ad9 /tests
parentab2c61e6384bbb5a0d154caa8f4784f9053147fe (diff)
Fix QApplication::font returns the font unstable according to the object
If a default font was not registered for the widget's class, it returns the default font of its nearest registered superclass. Fixes: QTBUG-89910 Pick-to: 5.15 6.0 Change-Id: I6e6b2c6a0044462f84db9f76a03be0c6cfaaae8e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
index 00e6adbc32..158e52bb92 100644
--- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
+++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
@@ -59,6 +59,7 @@
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QScrollArea>
#include <QtWidgets/QScrollBar>
+#include <QtWidgets/QHeaderView>
#include <QtWidgets/private/qapplication_p.h>
#include <QtWidgets/QStyle>
#include <QtWidgets/qproxystyle.h>
@@ -95,6 +96,7 @@ private slots:
void setFont_data();
void setFont();
+ void setFontForClass();
void args_data();
void args();
@@ -426,6 +428,46 @@ void tst_QApplication::setFont()
QCOMPARE( app.font(), font );
}
+class tstHeaderView : public QHeaderView
+{
+ Q_OBJECT
+public:
+ explicit tstHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr)
+ : QHeaderView(orientation, parent)
+ {}
+};
+class tstFrame : public QFrame { Q_OBJECT };
+class tstWidget : public QWidget { Q_OBJECT };
+
+void tst_QApplication::setFontForClass()
+{
+ // QTBUG-89910
+ // If a default font was not registered for the widget's class,
+ // it returns the default font of its nearest registered superclass.
+ int argc = 0;
+ QApplication app(argc, nullptr);
+
+ QFont font;
+ int pointSize = 10;
+ const QByteArrayList classNames{"QHeaderView", "QAbstractItemView", "QAbstractScrollView", "QFrame", "QWidget", "QObject"};
+ for (auto className : classNames) {
+ font.setPointSizeF(pointSize++);
+ app.setFont(font, className.constData());
+ }
+
+ tstHeaderView headView(Qt::Horizontal);
+ tstFrame frame;
+ tstWidget widget;
+
+ QFont headViewFont = QApplication::font(&headView);
+ QFont frameFont = QApplication::font(&frame);
+ QFont widgetFont = QApplication::font(&widget);
+
+ QCOMPARE(headViewFont.pointSize(), QApplication::font("QHeaderView").pointSize());
+ QCOMPARE(frameFont.pointSize(), QApplication::font("QFrame").pointSize());
+ QCOMPARE(widgetFont.pointSize(), QApplication::font("QWidget").pointSize());
+}
+
void tst_QApplication::args_data()
{
QTest::addColumn<int>("argc_in");