Ambiguous shortcut overload: F1
-
Hello everyone,
Could you please help me in clarifying one point. I have a set of Widgets (either default QWidget objects, or my custom ones which are derrived from QWidget, of course) and a widget (QWidget or QMainWindow) which contains some widgets from the set. Each widget has its own help window, which I invoke using this code in the object constructor:
QAction* helpAction = new QAction("Help", this); helpAction->setShortcut(QKeySequence::HelpContents); connect(helpAction, &QAction::triggered, this, [this]() { help(); }); addAction(helpAction);
And if I press F1 keyboard shortcut (which is default shortcut to open Help window on Windows) I get the message about overloading the same shortcut:
QAction::event: Ambiguous shortcut overload: F1
Which makes sense, of course. If there is only one widget then keyboard shortcut works.
But in my imagination the widget is in focus when the user interacts with it (press buttons, clicks on something, hovering mouse cursor), not when it is just placed on the widget. I wrong and I would like to know why. Also, I really want to know how I can change the focus (or whatever I need to change to make it works) to achieve the behavior when I have a lot of widgets in one widget and call specific widget relevant help window without getting an error.
-
Hello everyone,
Could you please help me in clarifying one point. I have a set of Widgets (either default QWidget objects, or my custom ones which are derrived from QWidget, of course) and a widget (QWidget or QMainWindow) which contains some widgets from the set. Each widget has its own help window, which I invoke using this code in the object constructor:
QAction* helpAction = new QAction("Help", this); helpAction->setShortcut(QKeySequence::HelpContents); connect(helpAction, &QAction::triggered, this, [this]() { help(); }); addAction(helpAction);
And if I press F1 keyboard shortcut (which is default shortcut to open Help window on Windows) I get the message about overloading the same shortcut:
QAction::event: Ambiguous shortcut overload: F1
Which makes sense, of course. If there is only one widget then keyboard shortcut works.
But in my imagination the widget is in focus when the user interacts with it (press buttons, clicks on something, hovering mouse cursor), not when it is just placed on the widget. I wrong and I would like to know why. Also, I really want to know how I can change the focus (or whatever I need to change to make it works) to achieve the behavior when I have a lot of widgets in one widget and call specific widget relevant help window without getting an error.
@serebryakov
I believe per QT - QAction::eventFilter: Ambiguous shortcut overload (from 11 years ago!) have you tried eitherQt::WidgetShortcut
or (more likely?)Qt::WidgetWithChildrenShortcut
? Otherwise from there what aboutQt::ApplicationShortcut
plus handling ineventFilter()
if you have to and the previous does not work? -
@serebryakov
I believe per QT - QAction::eventFilter: Ambiguous shortcut overload (from 11 years ago!) have you tried eitherQt::WidgetShortcut
or (more likely?)Qt::WidgetWithChildrenShortcut
? Otherwise from there what aboutQt::ApplicationShortcut
plus handling ineventFilter()
if you have to and the previous does not work?@JonB Thank you for your answer. I tried both
Qt::WidgetShortcut
andQt::WidgetWithChildrenShortcut
in the following way:helpAction->setShortcut(QKeySequence::HelpContents); helpAction->setShortcutContext(Qt::WidgetShortcut); // added this line connect(helpAction, &QAction::triggered, this, [this]() { QMessageBox::information(this, "Help", "Widget Two Help"); }); addAction(helpAction);
Unfortunately, it did not work.
@JonB said in Ambiguous shortcut overload: F1:
Qt::ApplicationShortcut plus handling in eventFilter()
Could you please provide more instructions of how I can implement it?
-
@JonB Thank you for your answer. I tried both
Qt::WidgetShortcut
andQt::WidgetWithChildrenShortcut
in the following way:helpAction->setShortcut(QKeySequence::HelpContents); helpAction->setShortcutContext(Qt::WidgetShortcut); // added this line connect(helpAction, &QAction::triggered, this, [this]() { QMessageBox::information(this, "Help", "Widget Two Help"); }); addAction(helpAction);
Unfortunately, it did not work.
@JonB said in Ambiguous shortcut overload: F1:
Qt::ApplicationShortcut plus handling in eventFilter()
Could you please provide more instructions of how I can implement it?
@serebryakov
I didn't try yours, or compare to their context. I assume you triedQt::WidgetWithChildrenShortcut
as well, since some of the answers suggested that was the way.If you have to do it via
Qt::ApplicationShortcut
pluseventFilter()
the reference I gave you has the code in the reply at https://stackoverflow.com/a/45596845/489865.You can look through other suggestions by Googling
QAction::event: Ambiguous shortcut overload
. I think the right solution depends on the context you are in in your UI.