summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChunLin Wang <wangchunlin@uniontech.com>2021-01-11 13:14:43 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-01-15 08:46:37 +0000
commitc00f52e821a3a982e91d9c4515c3d4d944305a16 (patch)
tree501a4264c8e189113e102d5cc991592486cb95cb /tests
parent5b3dbd38ca7685368c878dabcffeef2c3339711a (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 Change-Id: I6e6b2c6a0044462f84db9f76a03be0c6cfaaae8e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit dafd26acbe7b08f5ddfe60432fe0e49422ac085c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
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 6763d3b6a6..750810724c 100644
--- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
+++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
@@ -54,6 +54,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>
@@ -90,6 +91,7 @@ private slots:
void setFont_data();
void setFont();
+ void setFontForClass();
void args_data();
void args();
@@ -421,6 +423,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");