0
votes

I am having a Mouse Area, which should behave differently, depending on whether modifier keys are pressed. There should also be a default behaviour, when no modifier key is pressed. I test for this like this:

        MouseArea {
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            onPressed: {
                console.log('Entered onPressed: ', mouse.modifiers&Qt.NoModifier)
                if(mouse.modifiers & Qt.NoModifier) {
                    console.log('Entered If: ', mouse.modifiers&Qt.NoModifier)
                }
         }

When I then press the mouse button in the MouseArea I get the following output:

    qml: Entered onPressed:  0

But the second line is not printed. The problem seems to be that mouse.modifiers&Qt.NoModifier is evaluated to zero. In Contrast,

                if(mouse.modifiers & Qt.ControlModifier) {
                    console.log("Entered Control if: ",mouse.modifiers&Qt.ControlModifier)
                }

is working and prints qml: Entered Control if: 67108864 Shouldn't mouse.modifiers&Qt.NoModifier also get evaluated to something non zero?

1
If you look at how Qt flag fields are implemented, no flag is always zero, and each flag value occupies a bit position, so you can AND and OR the flags value. - dtech

1 Answers

0
votes

So it seems that Qt.NoModifer is zero, therfore mouse.modifiers&Qt.NoModifier is zero. Thus checking

 if(!mouse.modifiers)

should be the solution