From f64bd90920b80be63c318fed7613c87ff70cce1b Mon Sep 17 00:00:00 2001 From: Titta Heikkala Date: Wed, 30 Aug 2017 14:45:40 +0300 Subject: 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 --- examples/charts/chartthemes/themewidget.cpp | 62 ++++++++++++++++------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'examples') 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 #include #include +#include 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) -- cgit v1.2.3