Skip to content

Commit 1c95d1f

Browse files
committed
MainWindow (macOS): Defeat Qt's menu text heuristic
Workaround for QTBUG-30812. Resolves #1067.
1 parent b3cd92c commit 1c95d1f

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/gui/main_window.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012, 2013, 2014 Thomas Schöps
3-
* Copyright 2012-2017 Kai Pastor
3+
* Copyright 2012-2018 Kai Pastor
44
*
55
* This file is part of OpenOrienteering.
66
*
@@ -255,6 +255,26 @@ void MainWindow::setController(MainWindowController* new_controller, bool has_fi
255255
createHelpMenu();
256256

257257
#if defined(Q_OS_MACOS)
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.
263+
const auto menubar_actions = menuBar()->actions();
264+
for (auto action : menubar_actions)
265+
{
266+
if (const auto menu = action->menu())
267+
{
268+
const auto menu_actions = menu->actions();
269+
for (auto action : menu_actions)
270+
{
271+
static const auto zwsp = QString::fromUtf8("\u200B");
272+
action->setText(zwsp + action->text() + zwsp);
273+
}
274+
}
275+
}
276+
277+
// Needed to activate the menu bar changes
258278
if (isVisible() && qApp->activeWindow() == this)
259279
{
260280
// Force a menu synchronisation,

src/gui/map/map_editor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,6 @@ void MapEditorController::createActions()
871871

872872
show_grid_act = newCheckAction("showgrid", tr("Show grid"), this, SLOT(showGrid()), "grid.png", QString{}, "grid.html");
873873
configure_grid_act = newAction("configuregrid", tr("Configure grid..."), this, SLOT(configureGrid()), "grid.png", QString{}, "grid.html");
874-
#if defined(Q_OS_MACOS)
875-
configure_grid_act->setMenuRole(QAction::NoRole);
876-
#endif
877874
pan_act = newToolAction("panmap", tr("Pan"), this, SLOT(pan()), "move.png", QString{}, "view_menu.html");
878875
move_to_gps_pos_act = newAction("movegps", tr("Move to my location"), this, SLOT(moveToGpsPos()), "move-to-gps.png", QString{}, "view_menu.html");
879876
move_to_gps_pos_act->setEnabled(false);

0 commit comments

Comments
 (0)