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?

Mouse pressed with right OR left click check?

Scheduled Pinned Locked Moved Solved General and Desktop
clickqpushbuttright-click
5 Posts 3 Posters 7.3k 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.
  • L Offline
    L Offline
    legitnameyo
    wrote on 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!

    jsulmJ 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on 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

        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!

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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 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?

          jsulmJ 1 Reply Last reply
          0
          • L legitnameyo
            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?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #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

            • Login

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