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

Qt Widget QMenu will only use correct color if the QML Qt Lab Platform Menu was loaded (Windows 11 only)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.7, 6.4.0, 6.7.0 Beta1
    • None
    • Windows 11
    • Windows

    Description

      Qt Widget QMenu will only use correct color if the QML Qt Lab Platform Menu was loaded.

      This is a Windows 11-only issue.

      If developer create a regular Qt Widget project with QMenu, whatever the QMenu is a context menu or a QMenuBar menu, it will always using a incorrect color palette, with black text on deep blue background, and gray background:

      If user adds a QQmlApplicationEngine instance and add a MenuBar and any Menu entry from Qt.labs.platform, even if the QML part is not visible, the QtWidget window will now have its correct menu color palette:

      the sample code:

      #include "mainwindow.h"
      
      #include <QApplication>
      #include <QQmlApplicationEngine>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
      //    // Uncomment this QML part to get a correct *QtWidget* QMenu
      //    QQmlApplicationEngine engine;
      //    engine.loadData(R"(
      //    import QtQuick 2
      //    import QtQuick.Controls 2
      //    import Qt.labs.platform 1 as Platform
      
      //    ApplicationWindow{
      //        visible: true
      //        title: "Qt QML"
      //        width: 350
      //        height: 200
      //        color: systemPalette.window
      //        SystemPalette { id: systemPalette; }
      //        Platform.MenuBar {
      //            Platform.Menu {
      //                title: qsTr("&File")
      
      //                Platform.MenuItem {
      //                    text: qsTr("&Open")
      //                    shortcut: StandardKey.Open
      //                }
      //                Platform.MenuItem {
      //                    text: qsTr("&Quit")
      //                }
      //            }
      //        }
      //    }
      //    )");
      
          // a regular Qt Widget window created via the default QtCreator New Project wizard
          // and just add a menu via the designer so you can test it out.
          MainWindow w;
          w.show();
      
          return a.exec();
      }
      

      See the attached project (qtwidget-menubug.zip) for full code to reproduce this issue.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            blumia Gary Wang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes