diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-07-13 14:45:41 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-07-21 19:38:25 +0000 |
commit | 7218665699e31ac8eebab17afd684d1a56d12ac3 (patch) | |
tree | 2cd6912956cc45b101bf8c5d35663b797bf4619f /tests | |
parent | f459ab1a37354ffae8aec61ae5579ee7b5cceb01 (diff) |
Ensure styles always get to polish the application palette
Before 0a93db4d82c051164923a10e4382b12de9049b45 we would polish the
application palette even when it was the default palette, as we
always recreated the system palette each time a style was set.
After the change we skipped polishing the palette unless it was set
by the user, under the assumption that the style would set its
own default palette if it wanted to override the system palette.
This turned out to break the style's ability to slightly tweak the
palette via polish (versus the more full on standardPalette approach).
We now polish both the default palette and user palettes, and we do
so as part of the normal palette update logic. This ensures that
the style also gets a chance to polish the palette when the platform
theme changes.
The polish will not have an effect on the resolve mask of the palette,
as the polish is conceptually the same as a base palette, and should
not affect e.g. Qt::AA_SetPalette.
Fixes: QTBUG-85469
Fixes: QTBUG-85188
Change-Id: I869e9c442b177de4f1dc49eb75220709306f4d12
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 0bf120f5fd197cd215cd9520a494b162887d1ec4)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/kernel/qapplication/customstyle.json | 3 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp | 76 |
2 files changed, 79 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qapplication/customstyle.json b/tests/auto/widgets/kernel/qapplication/customstyle.json new file mode 100644 index 0000000000..35b80f636c --- /dev/null +++ b/tests/auto/widgets/kernel/qapplication/customstyle.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "customstyle" ] +} diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 6b1cf7e55b..e159e22d2a 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -26,6 +26,8 @@ ** ****************************************************************************/ +#define QT_STATICPLUGIN +#include <QtWidgets/qstyleplugin.h> #include <qdebug.h> @@ -54,6 +56,7 @@ #include <QtWidgets/QScrollBar> #include <QtWidgets/private/qapplication_p.h> #include <QtWidgets/QStyle> +#include <QtWidgets/qproxystyle.h> #include <qpa/qwindowsysteminterface.h> #include <qpa/qwindowsysteminterface_p.h> @@ -127,6 +130,7 @@ private slots: void task109149(); void style(); + void applicationPalettePolish(); void allWidgets(); void topLevelWidgets(); @@ -1812,6 +1816,78 @@ void tst_QApplication::style() QVERIFY(QApplication::style() != nullptr); } +class CustomStyle : public QProxyStyle +{ +public: + CustomStyle() : QProxyStyle("Windows") { Q_ASSERT(!polished); } + ~CustomStyle() { polished = 0; } + void polish(QPalette &palette) + { + polished++; + palette.setColor(QPalette::Active, QPalette::Link, Qt::red); + } + static int polished; +}; + +int CustomStyle::polished = 0; + +class CustomStylePlugin : public QStylePlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "customstyle.json") +public: + QStyle *create(const QString &) { return new CustomStyle; } +}; + +Q_IMPORT_PLUGIN(CustomStylePlugin) + +void tst_QApplication::applicationPalettePolish() +{ + int argc = 1; + +#if defined(QT_BUILD_INTERNAL) + { + qputenv("QT_DESKTOP_STYLE_KEY", "customstyle"); + QApplication app(argc, &argv0); + QVERIFY(CustomStyle::polished); + QVERIFY(!app.palette().resolve()); + QCOMPARE(app.palette().color(QPalette::Link), Qt::red); + qunsetenv("QT_DESKTOP_STYLE_KEY"); + } +#endif + + { + QApplication::setStyle(new CustomStyle); + QApplication app(argc, &argv0); + QVERIFY(CustomStyle::polished); + QVERIFY(!app.palette().resolve()); + QCOMPARE(app.palette().color(QPalette::Link), Qt::red); + } + + { + QApplication app(argc, &argv0); + app.setStyle(new CustomStyle); + QVERIFY(CustomStyle::polished); + QVERIFY(!app.palette().resolve()); + QCOMPARE(app.palette().color(QPalette::Link), Qt::red); + + CustomStyle::polished = 0; + app.setPalette(QPalette()); + QVERIFY(CustomStyle::polished); + QVERIFY(!app.palette().resolve()); + QCOMPARE(app.palette().color(QPalette::Link), Qt::red); + + CustomStyle::polished = 0; + QPalette palette; + palette.setColor(QPalette::Active, QPalette::Highlight, Qt::green); + app.setPalette(palette); + QVERIFY(CustomStyle::polished); + QVERIFY(app.palette().resolve()); + QCOMPARE(app.palette().color(QPalette::Link), Qt::red); + QCOMPARE(app.palette().color(QPalette::Highlight), Qt::green); + } +} + void tst_QApplication::allWidgets() { int argc = 1; |