KeyEvent QML Type

주요 이벤트에 대한 정보를 제공합니다. 자세히 보기...

Import Statement: import QtQuick

속성

방법

  • bool matches(StandardKey matchKey)

상세 설명

예를 들어 다음은 Enter 키를 누를 때 항목의 상태 속성을 변경하는 예시입니다:

Item {
    focus: true
    Keys.onPressed: (event)=> { if (event.key == Qt.Key_Enter) state = 'ShowDetails'; }
}

속성 문서

accepted : bool

accepted 을 true로 설정하면 키 이벤트가 항목의 부모로 전파되지 않습니다.

일반적으로 항목이 키 이벤트에 반응하는 경우 상위 항목도 동일한 이벤트에 반응하지 않도록 허용해야 합니다.


count : int [read-only]

이 속성은 이 이벤트에 관련된 키의 수를 보유합니다. KeyEvent::text 이 비어 있지 않으면 단순히 문자열의 길이입니다.


isAutoRepeat : bool [read-only]

이 속성은 이 이벤트가 자동 반복 키에서 발생했는지 여부를 보유합니다.


key : int [read-only]

이 속성은 눌렀거나 놓았던 키의 코드를 보유합니다.

키보드 코드 목록은 Qt.Key 을 참조하세요. 이 코드는 기본 창 시스템과는 독립적입니다. 이 함수는 대문자와 비대문자를 구분하지 않으므로 text 속성을 사용하세요.

0 또는 Qt.Key_Unknown 값은 해당 이벤트가 알려진 키의 결과가 아님을 의미합니다(예: 작성 시퀀스, 키보드 매크로 또는 키 이벤트 압축으로 인한 결과일 수 있음).


modifiers : int [read-only]

이 속성은 이벤트가 발생하기 직전에 존재했던 키보드 수정자 플래그를 보유합니다.

여기에는 숫자 값의 비트 단위 조합이 포함됩니다( Qt::KeyboardModifier 에서와 동일):

상수설명
Qt.NoModifier수정자 키가 눌리지 않았습니다.
Qt.ShiftModifier키보드의 Shift 키를 눌렀습니다.
Qt.ControlModifier키보드의 Ctrl 키를 누릅니다.
Qt.AltModifier키보드의 Alt 키를 눌렀습니다.
Qt.MetaModifier키보드의 메타 키를 누릅니다.
Qt.KeypadModifier키패드 버튼을 누릅니다.
Qt.GroupSwitchModifierX11에만 해당됩니다. 키보드의 Mode_switch 키를 누릅니다.

예를 들어 Shift 키 + Enter 키 조합에 반응합니다:

Item {
    focus: true
    Keys.onPressed: (event)=> {
        if ((event.key == Qt.Key_Enter) && (event.modifiers & Qt.ShiftModifier))
            doSomething();
    }
}

nativeScanCode : quint32 [read-only]

이 속성에는 눌렀던 키의 기본 스캔 코드가 포함됩니다. QKeyEvent 에서 변경되지 않은 상태로 전달됩니다.

QKeyEvent::nativeScanCode()도 참조하세요 .


text : string [read-only]

이 속성에는 키가 생성한 유니코드 텍스트가 저장됩니다. 시프트, 컨트롤, Alt, 메타 등의 수정자 키를 누르거나 놓는 경우 반환되는 텍스트는 빈 문자열일 수 있습니다. 이러한 경우 key 에는 유효한 값이 포함됩니다.


메서드 문서

bool matches(StandardKey matchKey)

키 이벤트가 주어진 표준 matchKey 과 일치하면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다.

Item {
    focus: true
    Keys.onPressed: (event)=> {
        if (event.matches(StandardKey.Undo))
            myModel.undo();
        else if (event.matches(StandardKey.Redo))
            myModel.redo();
    }
}

QKeySequence::StandardKey참조하세요 .


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.