Jelajahi Sumber

frontend: Set Frontend-API QActions role to NoRole

When no role is set, the default is QAction::TextHeuristicRole. This
means that the text of the item gets fuzzy-matched in Qt against a set
of possible strings that could indicate that the menu should be in the
application menu on macOS.
For us this meant however that on some languages, the translation of
"WebSocket Server Settings" would begin with "Config", and as such the
related QAction replaces our "Settings" action for the PreferencesRole,
and clicking "Preferences..." in the application menu would open the
websocket settings. It should probably be considered a bug in Qt that
implicit matches via TextHeuristicRole can overwrite ones that are
explicitly set (like our PreferencesRole). However we explicitly set our
roles ourselves anyways and there is no scenario where a  plugin should
overwrite them, we can just default actions added via the Frontend API
to be NoRole; and worry about the Qt bug later.
Sebastian Beckmann 4 bulan lalu
induk
melakukan
d3c5d2ce0b
2 mengubah file dengan 5 tambahan dan 1 penghapusan
  1. 4 1
      frontend/OBSStudioAPI.cpp
  2. 1 0
      frontend/widgets/OBSBasic_Docks.cpp

+ 4 - 1
frontend/OBSStudioAPI.cpp

@@ -314,7 +314,9 @@ bool OBSStudioAPI::obs_frontend_replay_buffer_active()
 void *OBSStudioAPI::obs_frontend_add_tools_menu_qaction(const char *name)
 {
 	main->ui->menuTools->setEnabled(true);
-	return (void *)main->ui->menuTools->addAction(QT_UTF8(name));
+	QAction *action = main->ui->menuTools->addAction(QT_UTF8(name));
+	action->setMenuRole(QAction::NoRole);
+	return static_cast<void *>(action);
 }
 
 void OBSStudioAPI::obs_frontend_add_tools_menu_item(const char *name, obs_frontend_cb callback, void *private_data)
@@ -326,6 +328,7 @@ void OBSStudioAPI::obs_frontend_add_tools_menu_item(const char *name, obs_fronte
 	};
 
 	QAction *action = main->ui->menuTools->addAction(QT_UTF8(name));
+	action->setMenuRole(QAction::NoRole);
 	QObject::connect(action, &QAction::triggered, func);
 }
 

+ 1 - 0
frontend/widgets/OBSBasic_Docks.cpp

@@ -210,6 +210,7 @@ QAction *OBSBasic::AddDockWidget(QDockWidget *dock)
 	QAction *action = ui->menuDocks->addAction(dock->windowTitle());
 #endif
 	action->setCheckable(true);
+	action->setMenuRole(QAction::NoRole);
 	assignDockToggle(dock, action);
 	oldExtraDocks.push_back(dock);
 	oldExtraDockNames.push_back(dock->objectName());