Quellcode durchsuchen

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.

Cherry Pick Note:
Manually picked due to UI code reorganization.

(cherry picked from commit d3c5d2ce0b15bac7a502f5aef4b3b5ec72ee8e09)
Sebastian Beckmann vor 4 Monaten
Ursprung
Commit
185e6097b0
2 geänderte Dateien mit 5 neuen und 1 gelöschten Zeilen
  1. 4 1
      UI/api-interface.cpp
  2. 1 0
      UI/window-basic-main.cpp

+ 4 - 1
UI/api-interface.cpp

@@ -284,7 +284,9 @@ struct OBSStudioAPI : obs_frontend_callbacks {
 	void *obs_frontend_add_tools_menu_qaction(const char *name) override
 	{
 		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 obs_frontend_add_tools_menu_item(const char *name, obs_frontend_cb callback, void *private_data) override
@@ -296,6 +298,7 @@ struct OBSStudioAPI : obs_frontend_callbacks {
 		};
 
 		QAction *action = main->ui->menuTools->addAction(QT_UTF8(name));
+		action->setMenuRole(QAction::NoRole);
 		QObject::connect(action, &QAction::triggered, func);
 	}
 

+ 1 - 0
UI/window-basic-main.cpp

@@ -9552,6 +9552,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());