summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorTitta Heikkala <titta.heikkala@qt.io>2017-08-30 14:45:40 +0300
committerTitta Heikkala <titta.heikkala@qt.io>2017-08-30 11:51:58 +0000
commitf64bd90920b80be63c318fed7613c87ff70cce1b (patch)
tree331a4af66867616754e30a44e036c4e5d57bc522 /examples
parentfea42978e68c967aa482dbd9a728c482c15e7858 (diff)
Fix window palette initialization in Chart Themes Example
The default window palette needs to be set to the application object in initialization as the palette of the window is not valid by then. Change-Id: Iad18c255600b31b18f0030094dd9e57757001fa1 Task-number: QTBUG-62824 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/charts/chartthemes/themewidget.cpp62
1 files changed, 35 insertions, 27 deletions
diff --git a/examples/charts/chartthemes/themewidget.cpp b/examples/charts/chartthemes/themewidget.cpp
index 28741443..bcdd2e7f 100644
--- a/examples/charts/chartthemes/themewidget.cpp
+++ b/examples/charts/chartthemes/themewidget.cpp
@@ -51,6 +51,7 @@
#include <QtWidgets/QLabel>
#include <QtCore/QRandomGenerator>
#include <QtCharts/QBarCategoryAxis>
+#include <QtWidgets/QApplication>
ThemeWidget::ThemeWidget(QWidget *parent) :
QWidget(parent),
@@ -111,6 +112,13 @@ ThemeWidget::ThemeWidget(QWidget *parent) :
// Set defaults
m_antialiasCheckBox->setChecked(true);
+
+ // Set the colors from the light theme as default ones
+ QPalette pal = qApp->palette();
+ pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
+ pal.setColor(QPalette::WindowText, QRgb(0x404044));
+ qApp->setPalette(pal);
+
updateUI();
}
@@ -332,35 +340,35 @@ void ThemeWidget::updateUI()
if (m_charts.at(0)->chart()->theme() != theme) {
for (QChartView *chartView : charts)
chartView->chart()->setTheme(theme);
- }
- QPalette pal = window()->palette();
- if (theme == QChart::ChartThemeLight) {
- pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
- pal.setColor(QPalette::WindowText, QRgb(0x404044));
- } else if (theme == QChart::ChartThemeDark) {
- pal.setColor(QPalette::Window, QRgb(0x121218));
- pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
- } else if (theme == QChart::ChartThemeBlueCerulean) {
- pal.setColor(QPalette::Window, QRgb(0x40434a));
- pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
- } else if (theme == QChart::ChartThemeBrownSand) {
- pal.setColor(QPalette::Window, QRgb(0x9e8965));
- pal.setColor(QPalette::WindowText, QRgb(0x404044));
- } else if (theme == QChart::ChartThemeBlueNcs) {
- pal.setColor(QPalette::Window, QRgb(0x018bba));
- pal.setColor(QPalette::WindowText, QRgb(0x404044));
- } else if (theme == QChart::ChartThemeHighContrast) {
- pal.setColor(QPalette::Window, QRgb(0xffab03));
- pal.setColor(QPalette::WindowText, QRgb(0x181818));
- } else if (theme == QChart::ChartThemeBlueIcy) {
- pal.setColor(QPalette::Window, QRgb(0xcee7f0));
- pal.setColor(QPalette::WindowText, QRgb(0x404044));
- } else {
- pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
- pal.setColor(QPalette::WindowText, QRgb(0x404044));
+ QPalette pal = window()->palette();
+ if (theme == QChart::ChartThemeLight) {
+ pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
+ pal.setColor(QPalette::WindowText, QRgb(0x404044));
+ } else if (theme == QChart::ChartThemeDark) {
+ pal.setColor(QPalette::Window, QRgb(0x121218));
+ pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
+ } else if (theme == QChart::ChartThemeBlueCerulean) {
+ pal.setColor(QPalette::Window, QRgb(0x40434a));
+ pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
+ } else if (theme == QChart::ChartThemeBrownSand) {
+ pal.setColor(QPalette::Window, QRgb(0x9e8965));
+ pal.setColor(QPalette::WindowText, QRgb(0x404044));
+ } else if (theme == QChart::ChartThemeBlueNcs) {
+ pal.setColor(QPalette::Window, QRgb(0x018bba));
+ pal.setColor(QPalette::WindowText, QRgb(0x404044));
+ } else if (theme == QChart::ChartThemeHighContrast) {
+ pal.setColor(QPalette::Window, QRgb(0xffab03));
+ pal.setColor(QPalette::WindowText, QRgb(0x181818));
+ } else if (theme == QChart::ChartThemeBlueIcy) {
+ pal.setColor(QPalette::Window, QRgb(0xcee7f0));
+ pal.setColor(QPalette::WindowText, QRgb(0x404044));
+ } else {
+ pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
+ pal.setColor(QPalette::WindowText, QRgb(0x404044));
+ }
+ window()->setPalette(pal);
}
- window()->setPalette(pal);
bool checked = m_antialiasCheckBox->isChecked();
for (QChartView *chart : charts)