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. [Solved] QAction - how to distinguish middle click
Forum Updated to NodeBB v4.3 + New Features

[Solved] QAction - how to distinguish middle click

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 6.5k 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.
  • N Offline
    N Offline
    nowrep
    wrote on last edited by
    #1

    Hello,
    is it possible to distinguish middle mouse click from normal (left) click on QAction in QMenu?
    I tried subclassing QAction and reimplementing event(QEvent*) function, but this function is called only once, on Action creation.

    Thanks for any help.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      event itself will not help, as it is no UI object. You could subclass QMenu and do it there.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nowrep
        wrote on last edited by
        #3

        Thanks for tip. Will test it and post results.

        EDIT: Thanks very much, it worked like charm :-)

        If someone want to see the code, there it is (I also subclassed QAction to support middleClicked() signal)
        @
        void Menu::mouseReleaseEvent(QMouseEvent e)
        {
        Action
        act = qobject_cast<Action*> (actionAt(e->pos()));

        if (!act) {
            QMenu::mouseReleaseEvent(e);
            return;
        }
        
        if (e->button() == Qt::LeftButton) {
            act->trigger();
            close();
            e->accept();
        }
        else if (e->button() == Qt::MiddleButton) {
            act->triggerMiddleClick();
            close();
            e->accept();
        }
        

        }
        @

        1 Reply Last reply
        1

        • Login

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