Mouse pressed with right OR left click check?
-
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!
-
Widgets or QML?
In general, if you implement the mouse event handling, you can get the button from the event object.
-
@legitnameyo You can use http://doc.qt.io/qt-5/qmouseevent.html#button to differentiate between left/right mouse button.
-
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?
-
@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