aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/doc/snippets/qml/focus/rectangle.qml
blob: 42646735812675b4ed74ef5fd0bbd3b605a48faf (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
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick

//! [simple key event]
Rectangle {
    width: 100; height: 100
    focus: true
    Keys.onPressed: (event)=> {
        if (event.key == Qt.Key_A) {
            console.log('Key A was pressed');
            event.accepted = true;
        }
    }
//! [simple key event]

//! [active focus]
    Text {
        text: activeFocus ? "I have active focus!" : "I do not have active focus"
    }
//! [active focus]

//! [simple key event end]
}
//! [simple key event end]