aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/quickcontrols/menus/cppsettings.cpp
diff options
context:
space:
mode:
authorMitch Curtis <[email protected]>2024-03-14 11:36:06 +0800
committerMitch Curtis <[email protected]>2024-04-17 15:05:01 +0800
commit822db20f84e188de0adb49741c751548d3c000ea (patch)
treefcb0d61de31ea91b9608642ca0c3ab81219364ac /tests/manual/quickcontrols/menus/cppsettings.cpp
parent55806207069a7014bde8785d7352e84f9e9f9406 (diff)
Menu, MenuBar: remove requestNative and rely solely on app attributes
It was decided that we'll have two attributes: - AA_DontUseNativeMenuBar - AA_DontUseNativeMenuWindows Setting AA_DontUseNativeMenuWindows only affects windows we create (context menus, combobox menus, menus of non-native menu bars). So, setting AA_DontUseNativeMenuWindows restores Qt to today's behavior. But we can't control the windows of native menu bars, so if you don't want those to be native, you have to set AA_DontUseNativeMenuBar just like today. By removing requestNative, we also effectively default to native menus and menu bars, as the attributes are not set by default. [ChangeLog][Controls][Important Behavior Changes] Menu and MenuBar now use native menus by default on platforms where they're supported. Task-number: QTBUG-69558 Change-Id: Ia917c2f820634def0cf815aa8ca8895ca79db75d Reviewed-by: Richard Moe Gustavsen <[email protected]>
Diffstat (limited to 'tests/manual/quickcontrols/menus/cppsettings.cpp')
-rw-r--r--tests/manual/quickcontrols/menus/cppsettings.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/manual/quickcontrols/menus/cppsettings.cpp b/tests/manual/quickcontrols/menus/cppsettings.cpp
new file mode 100644
index 0000000000..e06c59247f
--- /dev/null
+++ b/tests/manual/quickcontrols/menus/cppsettings.cpp
@@ -0,0 +1,46 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include "cppsettings.h"
+
+#include <QCoreApplication>
+
+CppSettings::CppSettings(QObject *parent) :
+ QObject(parent),
+ mSettings("QtProject", "menus")
+{
+ QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuWindows, dontUseNativeMenuWindows());
+ QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, dontUseNativeMenuBar());
+}
+
+bool CppSettings::dontUseNativeMenuWindows() const
+{
+ return mSettings.value("dontUseNativeMenuWindows").toBool();
+}
+
+void CppSettings::setDontUseNativeMenuWindows(bool dontUseNativeMenuWindows)
+{
+ const bool oldValue = this->dontUseNativeMenuWindows();
+ if (dontUseNativeMenuWindows == oldValue)
+ return;
+
+ QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuWindows, dontUseNativeMenuWindows);
+ mSettings.setValue("dontUseNativeMenuWindows", dontUseNativeMenuWindows);
+ emit dontUseNativeMenuWindowsChanged();
+}
+
+bool CppSettings::dontUseNativeMenuBar() const
+{
+ return mSettings.value("dontUseNativeMenuBar").toBool();
+}
+
+void CppSettings::setDontUseNativeMenuBar(bool dontUseNativeMenuBar)
+{
+ const bool oldValue = this->dontUseNativeMenuBar();
+ if (dontUseNativeMenuBar == oldValue)
+ return;
+
+ QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, dontUseNativeMenuBar);
+ mSettings.setValue("dontUseNativeMenuBar", dontUseNativeMenuBar);
+ emit dontUseNativeMenuBarChanged();
+}