Ali Hirani
Ali Hirani

Reputation: 301

Differentiate between Ctrl+Click and Right Click in Qt

I currently receive mouse events through a MouseArea in QML. I can distinguish between left, right and middle mouse press. On Mac, holding Control and Left Clicking is interpreted as a Qt.RightButton press. Is there anyway to distinguish between a standard Right Click and a (Ctrl + Left) Right Click? I need to do this to handle a custom UI interaction (I understand it's an Anti-pattern).

Note: In particular, I need to distinguish between a Ctrl + Left Click and a Ctrl + Right Click. As a result, simply detecting that Control is pressed while a right click event is received isn't good enough.

function button( mouse )
    {
        if( mouse.button == Qt.LeftButton )
        {
            console.log("left button is pressed");
            return 0;
        } else if( mouse.button == Qt.MidButton )
        {
            console.log("mid button");
            return 1;
        } else if ( mouse.button == Qt.RightButton )
        {
            console.log("right button pressed");
        }
 }

Upvotes: 1

Views: 1158

Answers (2)

ronso0
ronso0

Reputation: 11

Resolved (in a way...): this is a bug in Qt 5.12 which was fixed upstream already.

Upvotes: 0

On a Mac, holding Control and Left Clicking to do a Right Click is a system setting, and is a choice the user has - it has nothing to do with Qt, and attempting to detect it breaks your application, since the user depends on Ctrl+Left to act as Right, everywhere, and there's 0 reason for you to change that - just as there's zero reason to prevent the user from e.g. swapping left and right buttons globally (independent and unknown to your application), etc.

The mode of thinking you need is that Ctrl+Left is not available on a default Mac system, and indeed: why would it? If a cross-platform application uses Ctrl+Left/Right on Windows, I'd fully expect it to use Cmd+Left/Right on Mac, and would be quite confused if it did something else. Ctrl on Windows/Unix becomes Cmd on Mac - that's what everyone expects, that's how essentially everything works on Mac. That's what you want - and then there's no problem.

Upvotes: 4

Related Questions