Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Ambiguous shortcut overload: F1
Forum Updated to NodeBB v4.3 + New Features

Ambiguous shortcut overload: F1

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 533 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    serebryakov
    wrote on last edited by serebryakov
    #1

    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.

    JonBJ 1 Reply Last reply
    0
    • S serebryakov

      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.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @serebryakov
      I believe per QT - QAction::eventFilter: Ambiguous shortcut overload (from 11 years ago!) have you tried either Qt::WidgetShortcut or (more likely?) Qt::WidgetWithChildrenShortcut? Otherwise from there what about Qt::ApplicationShortcut plus handling in eventFilter() if you have to and the previous does not work?

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @serebryakov
        I believe per QT - QAction::eventFilter: Ambiguous shortcut overload (from 11 years ago!) have you tried either Qt::WidgetShortcut or (more likely?) Qt::WidgetWithChildrenShortcut? Otherwise from there what about Qt::ApplicationShortcut plus handling in eventFilter() if you have to and the previous does not work?

        S Offline
        S Offline
        serebryakov
        wrote on last edited by
        #3

        @JonB Thank you for your answer. I tried both Qt::WidgetShortcut and Qt::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?

        JonBJ 1 Reply Last reply
        0
        • S serebryakov

          @JonB Thank you for your answer. I tried both Qt::WidgetShortcut and Qt::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?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @serebryakov
          I didn't try yours, or compare to their context. I assume you tried Qt::WidgetWithChildrenShortcut as well, since some of the answers suggested that was the way.

          If you have to do it via Qt::ApplicationShortcut plus eventFilter() 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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved