Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-112636

QGuiApplication::setWindowIcon(...) only takes effect in the first two times.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.5.0
    • GUI: Other
    • None
    • windows11
    • Windows

    Description

      I changed the window icon when I switched between dark and light themes on Windows 11. However, it only takes effect for the first time.

      QGuiApplication app(argc, argv);
      
      // set window icon
      
      // first time(it work fine)
      app.setWindowIcon(QIcon(QPixmap(app.styleHints()->colorScheme() == Qt::ColorScheme::Dark ?
      	":/resources/onnx-white.svg" : ":/resources/onnx.svg")));
      
      // only work when first switched dark or light theme
      QObject::connect(app.styleHints(), &QStyleHints::colorSchemeChanged, &app,
      	[&app](Qt::ColorScheme colorScheme) {
      		qDebug() << "Color Scheme Changed: " << colorScheme;
      		if (colorScheme == Qt::ColorScheme::Dark)
      			app.setWindowIcon(QIcon(QPixmap(":/resources/onnx-white.svg")));
      		else if (colorScheme == Qt::ColorScheme::Light)
      			app.setWindowIcon(QIcon(QPixmap(":/resources/onnx.svg")));
      	});
      

      Attachments

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            peiqi.liu Peiqi Liu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: