summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-05-07 15:46:11 +0200
committerAndy Shaw <andy.shaw@qt.io>2020-05-15 18:46:39 +0200
commit9803ba9b6f74f5ac18220fe145fe1fe4c8f70910 (patch)
tree5e8ebce91c8d308bade5360f8affee7fa3092de8 /tests
parentbd3b978701c32b2e13da853f2064aab369e32745 (diff)
Deprecate QGuiApplication::paletteChanged() signal
Rather than have a paletteChanged() signal which can be connected to for tracking when the application palette has changed, then it is better to use the event that is sent to all windows and the application itself. That way it is easy for a window/widget or item that cares about the change to the application font to catch it in the event() function. [ChangeLog][QtGui][QGuiApplication] Deprecated paletteChanged() signal in favor of QEvent::ApplicationPaletteChanged. Change-Id: I95da211e30590e357007cc14d8ee266baceba7b3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 54ca37e638..991211062f 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -418,6 +418,7 @@ private slots:
void winIdAfterClose();
void receivesLanguageChangeEvent();
void receivesApplicationFontChangeEvent();
+ void receivesApplicationPaletteChangeEvent();
private:
bool ensureScreenSize(int width, int height);
@@ -4988,6 +4989,7 @@ void tst_QWidget::isOpaque()
QVERIFY(!::isOpaque(&widget));
QApplication::setPalette(old);
+ QApplication::sendPostedEvents(&widget, QEvent::ApplicationPaletteChange);
QCOMPARE(::isOpaque(&widget), old.color(QPalette::Window).alpha() == 255);
}
#endif
@@ -11662,6 +11664,7 @@ public:
ChangeEventWidget(QWidget *parent = nullptr) : QWidget(parent) {}
int languageChangeCount = 0;
int applicationFontChangeCount = 0;
+ int applicationPaletteChangeCount = 0;
protected:
bool event(QEvent *e) override
{
@@ -11669,6 +11672,8 @@ protected:
languageChangeCount++;
else if (e->type() == QEvent::ApplicationFontChange)
applicationFontChangeCount++;
+ else if (e->type() == QEvent::ApplicationPaletteChange)
+ applicationPaletteChangeCount++;
return QWidget::event(e);
}
};
@@ -11679,6 +11684,7 @@ public:
ChangeEventWindow(QWindow *parent = nullptr) : QWindow(parent) {}
int languageChangeCount = 0;
int applicationFontChangeCount = 0;
+ int applicationPaletteChangeCount = 0;
protected:
bool event(QEvent *e) override
{
@@ -11686,6 +11692,8 @@ protected:
languageChangeCount++;
else if (e->type() == QEvent::ApplicationFontChange)
applicationFontChangeCount++;
+ else if (e->type() == QEvent::ApplicationPaletteChange)
+ applicationPaletteChangeCount++;
return QWindow::event(e);
}
};
@@ -11739,5 +11747,32 @@ void tst_QWidget::receivesApplicationFontChangeEvent()
QApplication::setFont(origFont);
}
+void tst_QWidget::receivesApplicationPaletteChangeEvent()
+{
+ // Confirm that any QWindow or top level QWidget only gets a single
+ // ApplicationPaletteChange event when the font is changed
+ const QPalette origPalette = QApplication::palette();
+
+ ChangeEventWidget topLevel;
+ auto childWidget = new ChangeEventWidget(&topLevel);
+ topLevel.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
+ ChangeEventWindow ww;
+ ww.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&ww));
+ ChangeEventWidget topLevelNotShown;
+ QPalette changedPalette = origPalette;
+ changedPalette.setColor(QPalette::Base, Qt::red);
+ QApplication::setPalette(changedPalette);
+ QCoreApplication::sendPostedEvents(0, QEvent::ApplicationPaletteChange);
+ QCOMPARE(topLevel.applicationPaletteChangeCount, 1);
+ QCOMPARE(topLevelNotShown.applicationPaletteChangeCount, 1);
+ // QWidget should not be passing the event on automatically
+ QCOMPARE(childWidget->applicationPaletteChangeCount, 0);
+ QCOMPARE(ww.applicationPaletteChangeCount, 1);
+
+ QApplication::setPalette(origPalette);
+}
+
QTEST_MAIN(tst_QWidget)
#include "tst_qwidget.moc"