summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Hvaal <harald.hvaal@gmail.com>2015-03-28 21:03:29 +0100
committerHarald Hvaal <harald.hvaal@gmail.com>2015-04-20 06:39:31 +0000
commit8fb881900c7bb7895e7a2109a7dc880954bcf3a9 (patch)
treea2c11493971ee18987960c41e40d61c5204db3cc
parent6526a4e1367fa134ff29952fcbdd0d7cc937003f (diff)
Enable checking for whether the system palette was explicitly set
In order to obey a palette set globally on QApplication, an application attribute for checking if it's set at all is added. Task-number: QTBUG-39800 Change-Id: I26b965e6e18e0e1ca4df03cf343b3527df3636b2 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
-rw-r--r--src/corelib/global/qnamespace.h1
-rw-r--r--src/corelib/global/qnamespace.qdoc3
-rw-r--r--src/gui/kernel/qguiapplication.cpp1
-rw-r--r--src/widgets/kernel/qapplication.cpp1
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp17
5 files changed, 23 insertions, 0 deletions
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index 745fb442f2..79ddf81b38 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -492,6 +492,7 @@ public:
AA_UseOpenGLES = 16,
AA_UseSoftwareOpenGL = 17,
AA_ShareOpenGLContexts = 18,
+ AA_SetPalette = 19,
// Add new attributes before this line
AA_AttributeCount
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 8ebe0da11f..f9d968d47b 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -194,6 +194,9 @@
instances that belong to different top-level windows. This value has
been added in Qt 5.4.
+ \value AA_SetPalette Indicates whether a palette was explicitly set on the
+ QApplication/QGuiApplication. This value has been added in Qt 5.5.
+
The following values are obsolete:
\value AA_ImmediateWidgetCreation This attribute is no longer fully
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 3e2b692cd0..926ec16f19 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -2757,6 +2757,7 @@ void QGuiApplication::setPalette(const QPalette &pal)
else
*QGuiApplicationPrivate::app_pal = pal;
applicationResourceFlags |= ApplicationPaletteExplicitlySet;
+ QCoreApplication::setAttribute(Qt::AA_SetPalette);
emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal);
}
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 00f590ebc2..ed10beddd4 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -1508,6 +1508,7 @@ void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char*
QApplicationPrivate::set_pal = new QPalette(palette);
else
*QApplicationPrivate::set_pal = palette;
+ QCoreApplication::setAttribute(Qt::AA_SetPalette);
}
}
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
index b921e1519f..19365bffdd 100644
--- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
+++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
@@ -76,6 +76,7 @@ private slots:
void genericPluginsAndWindowSystemEvents();
void layoutDirection();
void globalShareContext();
+ void testSetPaletteAttribute();
void staticFunctions();
@@ -968,6 +969,22 @@ void tst_QGuiApplication::globalShareContext()
#endif
}
+void tst_QGuiApplication::testSetPaletteAttribute()
+{
+ QCoreApplication::setAttribute(Qt::AA_SetPalette, false);
+ int argc = 1;
+ char *argv[] = { const_cast<char*>("tst_qguiapplication") };
+
+ QGuiApplication app(argc, argv);
+
+ QVERIFY(!QCoreApplication::testAttribute(Qt::AA_SetPalette));
+ QPalette palette;
+ palette.setColor(QPalette::Foreground, Qt::red);
+ QGuiApplication::setPalette(palette);
+
+ QVERIFY(QCoreApplication::testAttribute(Qt::AA_SetPalette));
+}
+
// Test that static functions do not crash if there is no application instance.
void tst_QGuiApplication::staticFunctions()
{