From a53473052b2741884cb2ecf119ddfba686dbab71 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 11 Jun 2024 16:11:59 +0200 Subject: [PATCH] Widget gallery example: set color scheme before constructing UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On macOS, we see unexplained white flashes of the UI when overriding the scheme in the widget's constructor. This only happens when running the bundle, but not when running the executable. Work around that problem by setting the scheme immediately after constructing QApplication. Task-number: QTBUG-126248 Change-Id: I4a5fe467d628fca5e52e1e36f43af8143239c7fa Reviewed-by: Doris Verria Reviewed-by: Tor Arne Vestbø (cherry picked from commit 88322f69a20fddedd9c45a1bb25f6c1d2dcf31f9) Reviewed-by: Qt Cherry-pick Bot --- examples/widgets/gallery/main.cpp | 1 + examples/widgets/gallery/widgetgallery.cpp | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/widgets/gallery/main.cpp b/examples/widgets/gallery/main.cpp index 2677b3708cf..95fffbdd3c1 100644 --- a/examples/widgets/gallery/main.cpp +++ b/examples/widgets/gallery/main.cpp @@ -9,6 +9,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); + app.styleHints()->setColorScheme(Qt::ColorScheme::Dark); WidgetGallery gallery; gallery.show(); return QCoreApplication::exec(); diff --git a/examples/widgets/gallery/widgetgallery.cpp b/examples/widgets/gallery/widgetgallery.cpp index d38dcbd5e82..92c878fcb6e 100644 --- a/examples/widgets/gallery/widgetgallery.cpp +++ b/examples/widgets/gallery/widgetgallery.cpp @@ -140,9 +140,7 @@ WidgetGallery::WidgetGallery(QWidget *parent) colorSchemeComboBox->addItem(tr("Auto")); colorSchemeComboBox->addItem(tr("Light")); colorSchemeComboBox->addItem(tr("Dark")); - // override the color scheme to dark - qApp->styleHints()->setColorScheme(Qt::ColorScheme::Dark); - colorSchemeComboBox->setCurrentIndex(2); + colorSchemeComboBox->setCurrentIndex(static_cast(qApp->styleHints()->colorScheme())); auto colorSchemeLabel = createWidget1(tr("&Color Scheme:"), "colorSchemeLabel"); colorSchemeLabel->setBuddy(colorSchemeComboBox);