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. Shortcut to QAction not being triggered

Shortcut to QAction not being triggered

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.3k Views
  • 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.
  • qwasder85Q Offline
    qwasder85Q Offline
    qwasder85
    wrote on last edited by qwasder85
    #1

    I've defined a QAction (it's a member variable) like this:

    m_p_delete_template_action = new QAction(tr("Delete"));
    m_p_delete_template_action->setShortcut(QKeySequence(QKeySequence::Delete));
    
    connect( m_p_delete_template_action, &QAction::triggered, 
        this, &SessionTemplateEditor::slotDeleteTemplate, Qt::UniqueConnection );
    

    Then I've added the QAction to a context menu:

    m_p_context_menu = new QMenu(this);
    m_p_context_menu->addAction(m_p_export_template_action);
    m_p_context_menu->addSeparator();
    m_p_context_menu->addAction(m_p_delete_template_action);
    m_p_context_menu->addAction(m_p_export_template_action);
    m_p_context_menu->addSeparator();
    m_p_context_menu->addAction(m_p_delete_template_action);
    

    The context menu's parent widget is a QTableView (if that even matters). For some reason, the shortcut does not trigger at all. I don't manually handle keyboard focus anywhere.

    Any ideas?

    jsulmJ 1 Reply Last reply
    0
    • qwasder85Q Offline
      qwasder85Q Offline
      qwasder85
      wrote on last edited by
      #6

      Ah, you know what.
      Of course, it doesn't work. I added the QAction to the context menu, which isn't receiving my keyboard input. I have to add it to the QTableView as well.
      Sometimes it helps to just talk about an issue.

      J.HilkJ 1 Reply Last reply
      0
      • qwasder85Q qwasder85

        I've defined a QAction (it's a member variable) like this:

        m_p_delete_template_action = new QAction(tr("Delete"));
        m_p_delete_template_action->setShortcut(QKeySequence(QKeySequence::Delete));
        
        connect( m_p_delete_template_action, &QAction::triggered, 
            this, &SessionTemplateEditor::slotDeleteTemplate, Qt::UniqueConnection );
        

        Then I've added the QAction to a context menu:

        m_p_context_menu = new QMenu(this);
        m_p_context_menu->addAction(m_p_export_template_action);
        m_p_context_menu->addSeparator();
        m_p_context_menu->addAction(m_p_delete_template_action);
        m_p_context_menu->addAction(m_p_export_template_action);
        m_p_context_menu->addSeparator();
        m_p_context_menu->addAction(m_p_delete_template_action);
        

        The context menu's parent widget is a QTableView (if that even matters). For some reason, the shortcut does not trigger at all. I don't manually handle keyboard focus anywhere.

        Any ideas?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @qwasder85 said in Shortcut to QAction not being triggered:

        m_p_context_menu->addAction(m_p_delete_template_action); m_p_context_menu = new QMenu(this);

        Why do you create here a new instance?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        qwasder85Q 1 Reply Last reply
        1
        • jsulmJ jsulm

          @qwasder85 said in Shortcut to QAction not being triggered:

          m_p_context_menu->addAction(m_p_delete_template_action); m_p_context_menu = new QMenu(this);

          Why do you create here a new instance?

          qwasder85Q Offline
          qwasder85Q Offline
          qwasder85
          wrote on last edited by
          #3

          @jsulm Mistake when pasting the code here. :)

          jsulmJ 1 Reply Last reply
          0
          • qwasder85Q qwasder85

            @jsulm Mistake when pasting the code here. :)

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @qwasder85 Do other shortcuts you add work?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            qwasder85Q 1 Reply Last reply
            0
            • jsulmJ jsulm

              @qwasder85 Do other shortcuts you add work?

              qwasder85Q Offline
              qwasder85Q Offline
              qwasder85
              wrote on last edited by
              #5

              @jsulm Hm, no.

              1 Reply Last reply
              0
              • qwasder85Q Offline
                qwasder85Q Offline
                qwasder85
                wrote on last edited by
                #6

                Ah, you know what.
                Of course, it doesn't work. I added the QAction to the context menu, which isn't receiving my keyboard input. I have to add it to the QTableView as well.
                Sometimes it helps to just talk about an issue.

                J.HilkJ 1 Reply Last reply
                0
                • qwasder85Q qwasder85

                  Ah, you know what.
                  Of course, it doesn't work. I added the QAction to the context menu, which isn't receiving my keyboard input. I have to add it to the QTableView as well.
                  Sometimes it helps to just talk about an issue.

                  J.HilkJ Online
                  J.HilkJ Online
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #7

                  @qwasder85 said in Shortcut to QAction not being triggered:

                  Ah, you know what.
                  Of course, it doesn't work. I added the QAction to the context menu, which isn't receiving my keyboard input. I have to add it to the QTableView as well.
                  Sometimes it helps to just talk about an issue.

                  It's called Rubber Duck Debugging

                  Don't forget to set the topic to solved :)


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  6

                  • Login

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