aboutsummaryrefslogtreecommitdiffstats
path: root/qt-qml/tests/manual/qml-syntax/signal-handler.qml
blob: be55288ad5a6be011464a991625e441ed0e0e27d (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
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import QtQuick

Rectangle {
    id: _rect

    // prop. changed signal handler
    onWidthChanged: _rect.pressed()
    onWidthChanged: {
        console.log(`width changed to ${_rect.width}`)
    }

    // item specific signal handler
    MouseArea {
        onClicked: (mouse) => {
            console.log("clicked")
            _rect.clickedAt(mouse.x, mouse.y)
        }
    }

    // attached signal handler
    Keys.onLeftPressed: console.log("move left")

    Keys.onPressed: (event) => {
        if (event.key == Qt.Key_Left) {
            console.log("move left");
            event.accepted = true;
        }
    }

    Component.onCompleted: {
        console.log("onCompleted")
    }
}