ui: Prevent Qt from automatically assigning Menu roles

Qt defaults to give every QAction a TextHeuristicRole, which means that certain key words will cause Qt to change how the QAction behaves. We do not want this, so we explicitly assign it to have NoRole instead.

Fixes #323
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-04-19 14:01:09 +02:00
parent 465158476a
commit ba61329dd1
2 changed files with 12 additions and 0 deletions

View file

@ -136,20 +136,25 @@ streamfx::ui::updater::updater(QMenu* menu)
// Check for Updates // Check for Updates
_cfu = menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHECKFORUPDATES))); _cfu = menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHECKFORUPDATES)));
_cfu->setMenuRole(QAction::NoRole);
connect(_cfu, &QAction::triggered, this, &streamfx::ui::updater::on_cfu_triggered); connect(_cfu, &QAction::triggered, this, &streamfx::ui::updater::on_cfu_triggered);
// Automatically check for Updates // Automatically check for Updates
_cfu_auto = menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHECKFORUPDATES_AUTOMATICALLY))); _cfu_auto = menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHECKFORUPDATES_AUTOMATICALLY)));
_cfu_auto->setMenuRole(QAction::NoRole);
_cfu_auto->setCheckable(true); _cfu_auto->setCheckable(true);
connect(_cfu_auto, &QAction::toggled, this, &streamfx::ui::updater::on_cfu_auto_toggled); connect(_cfu_auto, &QAction::toggled, this, &streamfx::ui::updater::on_cfu_auto_toggled);
// Update Channel // Update Channel
_channel_menu = menu->addMenu(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL))); _channel_menu = menu->addMenu(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL)));
_channel_menu->menuAction()->setMenuRole(QAction::NoRole);
_channel_stable = _channel_menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL_RELEASE))); _channel_stable = _channel_menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL_RELEASE)));
_channel_stable->setMenuRole(QAction::NoRole);
_channel_stable->setCheckable(true); _channel_stable->setCheckable(true);
_channel_preview = _channel_menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL_TESTING))); _channel_preview = _channel_menu->addAction(QString::fromUtf8(D_TRANSLATE(D_I18N_MENU_CHANNEL_TESTING)));
_channel_preview->setMenuRole(QAction::NoRole);
_channel_preview->setCheckable(true); _channel_preview->setCheckable(true);
_channel_group = new QActionGroup(_channel_menu); _channel_group = new QActionGroup(_channel_menu);

View file

@ -126,24 +126,29 @@ void streamfx::ui::handler::on_obs_loaded()
// Report an Issue // Report an Issue
_report_issue = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_report_issue.data()))); _report_issue = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_report_issue.data())));
_report_issue->setMenuRole(QAction::NoRole);
connect(_report_issue, &QAction::triggered, this, &streamfx::ui::handler::on_action_report_issue); connect(_report_issue, &QAction::triggered, this, &streamfx::ui::handler::on_action_report_issue);
// Request help // Request help
_request_help = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_request_help.data()))); _request_help = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_request_help.data())));
_request_help->setMenuRole(QAction::NoRole);
connect(_request_help, &QAction::triggered, this, &streamfx::ui::handler::on_action_request_help); connect(_request_help, &QAction::triggered, this, &streamfx::ui::handler::on_action_request_help);
_menu->addSeparator(); _menu->addSeparator();
// Website // Website
_link_website = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_website.data()))); _link_website = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_website.data())));
_link_website->setMenuRole(QAction::NoRole);
connect(_link_website, &QAction::triggered, this, &streamfx::ui::handler::on_action_website); connect(_link_website, &QAction::triggered, this, &streamfx::ui::handler::on_action_website);
// Discord // Discord
_link_discord = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_discord.data()))); _link_discord = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_discord.data())));
_link_discord->setMenuRole(QAction::NoRole);
connect(_link_discord, &QAction::triggered, this, &streamfx::ui::handler::on_action_discord); connect(_link_discord, &QAction::triggered, this, &streamfx::ui::handler::on_action_discord);
// Github // Github
_link_github = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_github.data()))); _link_github = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_github.data())));
_link_github->setMenuRole(QAction::NoRole);
connect(_link_github, &QAction::triggered, this, &streamfx::ui::handler::on_action_github); connect(_link_github, &QAction::triggered, this, &streamfx::ui::handler::on_action_github);
// Create the updater. // Create the updater.
@ -155,12 +160,14 @@ void streamfx::ui::handler::on_obs_loaded()
// About // About
_about_action = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_about.data()))); _about_action = _menu->addAction(QString::fromUtf8(D_TRANSLATE(_i18n_menu_about.data())));
_about_action->setMenuRole(QAction::NoRole);
connect(_about_action, &QAction::triggered, this, &streamfx::ui::handler::on_action_about); connect(_about_action, &QAction::triggered, this, &streamfx::ui::handler::on_action_about);
} }
{ // Add an actual Menu entry. { // Add an actual Menu entry.
QMainWindow* main_widget = reinterpret_cast<QMainWindow*>(obs_frontend_get_main_window()); QMainWindow* main_widget = reinterpret_cast<QMainWindow*>(obs_frontend_get_main_window());
_menu_action = new QAction(main_widget); _menu_action = new QAction(main_widget);
_menu_action->setMenuRole(QAction::NoRole);
_menu_action->setMenu(_menu); _menu_action->setMenu(_menu);
_menu_action->setText(QString::fromUtf8(D_TRANSLATE(_i18n_menu.data()))); _menu_action->setText(QString::fromUtf8(D_TRANSLATE(_i18n_menu.data())));