summaryrefslogtreecommitdiffstats
path: root/examples/declarative/mouseregion/mouse.qml
blob: 6d10425861737b4b7bf01a8ecf695dda0d2c37c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Rect {
    color: "white"
    width: 200
    height: 200
    Rect {
        width: 50
        height: 50
        color: "red"
        Text {
            text: "Click"
            anchors.centeredIn: parent
        }
        MouseRegion {
            onPressed: { print('press (x: ' + mouse.x + ' y: ' + mouse.y + ' button: ' + (mouse.button == Qt.RightButton ? 'right' : 'left') + ' Shift: ' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')') }
            onReleased: { print('release (x: ' + mouse.x + ' y: ' + mouse.y + ' isClick: ' + mouse.isClick + ' wasHeld: ' + mouse.wasHeld + ')') }
            onClicked: { print('click (x: ' + mouse.x + ' y: ' + mouse.y + ' wasHeld: ' + mouse.wasHeld + ')') }
            onDoubleClicked: { print('double click (x: ' + mouse.x + ' y: ' + mouse.y + ')') }
            onPressAndHold: { print('press and hold') }
            onExitedWhilePressed: { print('exiting while pressed') }
            onReenteredWhilePressed: { print('reentering while pressed') }
            anchors.fill: parent
        }
    }
    Rect {
        y: 100
        width: 50
        height: 50
        color: "blue"
        Text {
            text: "Drag"
            anchors.centeredIn: parent
        }
        MouseRegion {
            drag.target: parent
            drag.axis: "x"
            drag.xmin: 0
            drag.xmax: 150
            onPressed: { print('press') }
            onReleased: { print('release (isClick: ' + mouse.isClick + ') (wasHeld: ' + mouse.wasHeld + ')') }
            onClicked: { print('click' + '(wasHeld: ' + mouse.wasHeld + ')') }
            onDoubleClicked: { print('double click') }
            onPressAndHold: { print('press and hold') }
            onExitedWhilePressed: { print('exiting while pressed') }
            onReenteredWhilePressed: { print('reentering while pressed') }
            anchors.fill: parent
        }
    }
}