Qml에서 키보드 입력 이벤트를 핸들링하는 방법이다. 아래 예제 소스코드를 보자!
main.cpp에서는 main.qml을 로드한다.
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }
main.qml에서 키이벤트를 핸들링 하기위한 Item을 추가했으며 keys.onPressed 시그널에 대한 처리를 구현하였다.
import QtQuick 2.11 import QtQuick.Window 2.11 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Text { id: idText text: qsTr("text") anchors.centerIn: parent font.pixelSize: 15 } Item { focus: true Keys.onPressed: { switch(event.key){ case Qt.Key_A : idText.text = "input A key" break; case Qt.Key_0 : idText.text = "input num0 key" break; default: break; } } } }
키보드의 "a" 키 또는 숫자 "0"키가 눌려지면 가운데 텍스트를 바꾼다.
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
공지 | Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서 | 운영자 | 2019.01.05 | 86178 |
8 | QML에서 Websocket 서버와 통신 | makersweb | 2021.09.18 | 834 |
7 | QML에서 D-Bus 통신 | makersweb | 2023.03.15 | 711 |
6 | OpacityMask 예제 | makersweb | 2023.01.26 | 656 |
5 | QML과 코루틴(Coroutines) | makersweb | 2020.11.03 | 581 |
4 | 앱을 종료할 때 QML 바인딩 오류를 피하는 방법 | makersweb | 2021.08.08 | 499 |
3 | QtQuick 애플리케이션에 Rive 애니메이션 통합 | makersweb | 2024.03.31 | 483 |
2 | Binding 타입으로 객체 속성 간 묶기 | makersweb | 2022.03.04 | 428 |
1 | 그래픽 소프트웨어에서 디자인 내보내기 (Exporting Designs from Graphics Software) | j2doll | 2020.12.25 | 416 |