Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
None
-
5.15.7, 6.4.0, 6.7.0 Beta1
-
None
-
Windows 11
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.