1
1
/*
2
2
* Copyright 2012, 2013, 2014 Thomas Schöps
3
- * Copyright 2012-2017 Kai Pastor
3
+ * Copyright 2012-2018 Kai Pastor
4
4
*
5
5
* This file is part of OpenOrienteering.
6
6
*
@@ -255,10 +255,11 @@ void MainWindow::setController(MainWindowController* new_controller, bool has_fi
255
255
createHelpMenu ();
256
256
257
257
#if defined(Q_OS_MACOS)
258
- // Disable all menu text heuristics, as a workaround for QTBUG-30812.
259
- // Note that QAction::NoRole triggers QTBUG-29051,
260
- // warnings in QCocoaMenuItem::sync() about menu items having
261
- // "unsupported role QPlatformMenuItem::MenuRole(NoRole)".
258
+ // Defeat Qt's menu text heuristic, as a workaround for QTBUG-30812.
259
+ // Changing an action's menu role (to QAction::NoRole) after it was
260
+ // added to the menu is unsupported and triggers crashes (#1077).
261
+ // Instead, we defeat the heuristic by adding a zero width space at the
262
+ // beginning and the end of the text of every action in the menus.
262
263
const auto menubar_actions = menuBar ()->actions ();
263
264
for (auto action : menubar_actions)
264
265
{
@@ -267,15 +268,13 @@ void MainWindow::setController(MainWindowController* new_controller, bool has_fi
267
268
const auto menu_actions = menu->actions ();
268
269
for (auto action : menu_actions)
269
270
{
270
- if (action-> menuRole () == QAction::TextHeuristicRole)
271
- action->setMenuRole (QAction::NoRole );
271
+ static const auto zwsp = QString::fromUtf8 ( " \u200B " );
272
+ action->setText (zwsp + action-> text () + zwsp );
272
273
}
273
274
}
274
275
}
275
276
276
- // Probably related to QTBUG-62260.
277
- // But even with Qt 5.9.3, the "Mapper" menu is not correct initially.
278
- // (In Czech translation, the Settings menu is missing initially.)
277
+ // Needed to activate the menu bar changes
279
278
if (isVisible () && qApp->activeWindow () == this )
280
279
{
281
280
// Force a menu synchronisation,
0 commit comments