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. Mouse pressed with right OR left click check?
QtWS25 Last Chance

Mouse pressed with right OR left click check?

Scheduled Pinned Locked Moved Solved General and Desktop
clickqpushbuttright-click
5 Posts 3 Posters 6.5k 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.
  • L Offline
    L Offline
    legitnameyo
    wrote on 7 Feb 2019, 07:33 last edited by
    #1

    I have a button, which I want to do one action when left clicked and another action on right click, is that possible? I can only find examples of people replacing the left click with the right click but no examples of people actually creating a button with both! Thanks!

    J 1 Reply Last reply 7 Feb 2019, 07:38
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 7 Feb 2019, 07:37 last edited by
      #2

      Widgets or QML?

      In general, if you implement the mouse event handling, you can get the button from the event object.

      (Z(:^

      1 Reply Last reply
      3
      • L legitnameyo
        7 Feb 2019, 07:33

        I have a button, which I want to do one action when left clicked and another action on right click, is that possible? I can only find examples of people replacing the left click with the right click but no examples of people actually creating a button with both! Thanks!

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 7 Feb 2019, 07:38 last edited by
        #3

        @legitnameyo You can use http://doc.qt.io/qt-5/qmouseevent.html#button to differentiate between left/right mouse button.

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

        1 Reply Last reply
        3
        • L Offline
          L Offline
          legitnameyo
          wrote on 7 Feb 2019, 08:03 last edited by
          #4
          QMouseEvent btn = new QMouseEvent::QEvent(QEvent::MouseButtonPress*);
          qDebug() << btn.button();
          

          Gives me the error:

          expected expression
          

          I've read the doc's and it siad to give a QEvent, but that gave me a big error, so I changed it to the above. Am I missing something here?

          J 1 Reply Last reply 7 Feb 2019, 08:12
          0
          • L legitnameyo
            7 Feb 2019, 08:03
            QMouseEvent btn = new QMouseEvent::QEvent(QEvent::MouseButtonPress*);
            qDebug() << btn.button();
            

            Gives me the error:

            expected expression
            

            I've read the doc's and it siad to give a QEvent, but that gave me a big error, so I changed it to the above. Am I missing something here?

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 7 Feb 2019, 08:12 last edited by jsulm 2 Jul 2019, 08:16
            #5

            @legitnameyo This is not how it works. You will need to subclass QPushButton and override http://doc.qt.io/qt-5/qwidget.html#mousePressEvent
            You can find an example here: http://doc.qt.io/qt-5/qtwidgets-widgets-scribble-example.html

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

            1 Reply Last reply
            3

            3/5

            7 Feb 2019, 07:38

            • Login

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