QGuiApplication, platform plugins: don't modify AA_DontUseNativeMenuBar

The default should be false, meaning the application will prefer to
use a native menubar if the platform supports it.  The application
author can set it to true if he wants to always use a Qt-rendered
menubar instead; or, he can call QMenuBar::setNativeMenuBar().
Qt and its plugins should not override the author's wishes.
Instead, if the platform plugin cannot create a native menubar
for whatever reason, createPlatformMenuBar() will return null,
and QMenuBar will fall back to using a Qt menubar instead.
The application can check the result via QMenuBar::isNativeMenuBar().

QMdiArea when maximized inside a QMainWindow with an empty title
does not replace the main window's title if we are using native menus.
This behavior turned out to be the same on Unity as it is on macOS,
so the autotest needed adjustment to expect that behavior whenever
the menubar is native, not only on certain platforms.

tst_QMenuBar::allowActiveAndDisabled() tests a standalone QMenuBar.
In f92f78094 it was disabled on macOS, but on Ubuntu it passes as
long as we force it to be a non-native menubar, so it should pass
that way on macOS too.  Removed unused variable RESET to fix warning.

Task-number: QTBUG-54793
Change-Id: I716e40da709f96331cbbf25213bd7bc153e4dbe2
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
bb10
Shawn Rutledge 2016-09-15 14:07:07 +02:00 committed by Shawn Rutledge
parent 680dd3313c
commit 8cd28ea885
5 changed files with 40 additions and 54 deletions

View File

@ -1192,12 +1192,6 @@ static void init_plugins(const QList<QByteArray> &pluginList)
void QGuiApplicationPrivate::createPlatformIntegration()
{
// Use the Qt menus by default. Platform plugins that
// want to enable a native menu implementation can clear
// this flag.
QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
QHighDpiScaling::initHighDpiScaling();
// Load the platform integration

View File

@ -368,9 +368,6 @@ QAndroidPlatformTheme::QAndroidPlatformTheme(QAndroidPlatformNativeInterface *an
// default in case the style has not set a font
m_systemFont = QFont(QLatin1String("Roboto"), 14.0 * 100 / 72); // keep default size the same after changing from 100 dpi to 72 dpi
// by default use native menu bar
QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, false);
}
QPlatformMenuBar *QAndroidPlatformTheme::createPlatformMenuBar() const

View File

@ -300,8 +300,6 @@ QCocoaIntegration::QCocoaIntegration(const QStringList &paramList)
initResources();
QMacAutoReleasePool pool;
qApp->setAttribute(Qt::AA_DontUseNativeMenuBar, false);
NSApplication *cocoaApplication = [QNSApplication sharedApplication];
qt_redirectNSApplicationSendEvent();

View File

@ -359,25 +359,25 @@ void tst_QMdiSubWindow::mainWindowSupport()
mainWindow.show();
mainWindow.menuBar()->setVisible(true);
qApp->setActiveWindow(&mainWindow);
bool nativeMenuBar = mainWindow.menuBar()->isNativeMenuBar();
// QMainWindow's window title is empty
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
{
QCOMPARE(mainWindow.windowTitle(), QString());
QMdiSubWindow *window = workspace->addSubWindow(new QPushButton(QLatin1String("Test")));
QString expectedTitle = QLatin1String("MainWindow's title is empty");
window->setWindowTitle(expectedTitle);
QCOMPARE(window->windowTitle(), expectedTitle);
window->showMaximized();
QVERIFY(window->isMaximized());
QCOMPARE(window->windowTitle(), expectedTitle);
QCOMPARE(mainWindow.windowTitle(), expectedTitle);
window->showNormal();
QCOMPARE(window->windowTitle(), expectedTitle);
QCOMPARE(mainWindow.windowTitle(), QString());
window->close();
// QMainWindow's window title is empty, so on a platform which does NOT have a native menubar,
// the maximized subwindow's title is imposed onto the main window's titlebar.
if (!nativeMenuBar) {
QCOMPARE(mainWindow.windowTitle(), QString());
QMdiSubWindow *window = workspace->addSubWindow(new QPushButton(QLatin1String("Test")));
QString expectedTitle = QLatin1String("MainWindow's title is empty");
window->setWindowTitle(expectedTitle);
QCOMPARE(window->windowTitle(), expectedTitle);
window->showMaximized();
QVERIFY(window->isMaximized());
QCOMPARE(window->windowTitle(), expectedTitle);
QCOMPARE(mainWindow.windowTitle(), expectedTitle);
window->showNormal();
QCOMPARE(window->windowTitle(), expectedTitle);
QCOMPARE(mainWindow.windowTitle(), QString());
window->close();
}
#endif
QString originalWindowTitle = QString::fromLatin1("MainWindow");
mainWindow.setWindowTitle(originalWindowTitle);
@ -413,16 +413,16 @@ void tst_QMdiSubWindow::mainWindowSupport()
window->showMaximized();
qApp->processEvents();
QVERIFY(window->isMaximized());
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
QVERIFY(window->maximizedButtonsWidget());
QCOMPARE(window->maximizedButtonsWidget(), mainWindow.menuBar()->cornerWidget(Qt::TopRightCorner));
QVERIFY(window->maximizedSystemMenuIconWidget());
QCOMPARE(window->maximizedSystemMenuIconWidget(), qobject_cast<QWidget *>(mainWindow.menuBar()
->cornerWidget(Qt::TopLeftCorner)));
const QString expectedTitle = originalWindowTitle + QLatin1String(" - [")
+ window->widget()->windowTitle() + QLatin1Char(']');
QCOMPARE(mainWindow.windowTitle(), expectedTitle);
#endif
if (!nativeMenuBar) {
QVERIFY(window->maximizedButtonsWidget());
QCOMPARE(window->maximizedButtonsWidget(), mainWindow.menuBar()->cornerWidget(Qt::TopRightCorner));
QVERIFY(window->maximizedSystemMenuIconWidget());
QCOMPARE(window->maximizedSystemMenuIconWidget(),
qobject_cast<QWidget *>(mainWindow.menuBar()->cornerWidget(Qt::TopLeftCorner)));
const QString expectedTitle = originalWindowTitle + QLatin1String(" - [")
+ window->widget()->windowTitle() + QLatin1Char(']');
QCOMPARE(mainWindow.windowTitle(), expectedTitle);
}
// Check that nested child windows don't set window title
nestedWorkspace->show();
@ -436,15 +436,14 @@ void tst_QMdiSubWindow::mainWindowSupport()
QVERIFY(!nestedWindow->maximizedButtonsWidget());
QVERIFY(!nestedWindow->maximizedSystemMenuIconWidget());
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) && !defined(Q_OS_QNX)
QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]")
.arg(originalWindowTitle, window->widget()->windowTitle()));
#endif
if (!nativeMenuBar) {
QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]")
.arg(originalWindowTitle, window->widget()->windowTitle()));
}
}
#if defined(Q_OS_MAC) || defined(Q_OS_WINCE)
return;
#endif
if (nativeMenuBar)
return;
workspace->activateNextSubWindow();
qApp->processEvents();
@ -1911,14 +1910,14 @@ void tst_QMdiSubWindow::mdiArea()
void tst_QMdiSubWindow::task_182852()
{
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
QMdiArea *workspace = new QMdiArea;
QMainWindow mainWindow;
mainWindow.setCentralWidget(workspace);
mainWindow.show();
mainWindow.menuBar()->setVisible(true);
qApp->setActiveWindow(&mainWindow);
if (mainWindow.menuBar()->isNativeMenuBar())
return; // The main window's title is not overwritten if we have a native menubar (macOS, Unity etc.)
QString originalWindowTitle = QString::fromLatin1("MainWindow - [foo]");
mainWindow.setWindowTitle(originalWindowTitle);
@ -1954,9 +1953,6 @@ void tst_QMdiSubWindow::task_182852()
QCOMPARE(mainWindow.windowTitle(), QString::fromLatin1("%1 - [%2]")
.arg(originalWindowTitle, window->widget()->windowTitle()));
#endif
}
void tst_QMdiSubWindow::task_233197()

View File

@ -93,7 +93,6 @@ private slots:
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
void accel();
void activatedCount();
void allowActiveAndDisabled();
void check_accelKeys();
void check_cursorKeys1();
@ -102,6 +101,9 @@ private slots:
void check_escKey();
#endif
#ifndef Q_OS_WINCE
void allowActiveAndDisabled();
#endif
void check_endKey();
void check_homeKey();
@ -164,8 +166,6 @@ void tst_QMenuBar::getSetCheck()
#include <qcursor.h>
const int RESET = 0;
/*!
Test plan:
insertItem (all flavors and combinations)
@ -920,10 +920,11 @@ void tst_QMenuBar::check_escKey()
// QCOMPARE(m_complexActionTriggerCount['h'], (uint)itemH_count);
// }
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
#ifndef Q_OS_WINCE
void tst_QMenuBar::allowActiveAndDisabled()
{
QMenuBar menuBar;
menuBar.setNativeMenuBar(false);
// Task 241043 : check that second menu is activated if only
// disabled menu items are added