Widget gallery example: set color scheme before constructing UI

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.

Pick-to: 6.8
Task-number: QTBUG-126248
Change-Id: I4a5fe467d628fca5e52e1e36f43af8143239c7fa
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Volker Hilsheimer 2024-06-11 16:11:59 +02:00
parent 8b0f56e998
commit 88322f69a2
2 changed files with 2 additions and 3 deletions

View File

@ -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();

View File

@ -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<int>(qApp->styleHints()->colorScheme()));
auto colorSchemeLabel = createWidget1<QLabel>(tr("&Color Scheme:"), "colorSchemeLabel");
colorSchemeLabel->setBuddy(colorSchemeComboBox);