가상 키보드 Qt Quick

이 예는 Qt Quick 애플리케이션에서 가상 키보드를 사용하는 방법을 보여줍니다.

이 예제에는 데스크톱 플랫폼용과 임베디드 플랫폼용의 두 가지 구현이 있습니다. 전자는 가상 키보드를 사용하여 여러 텍스트 필드에 텍스트를 입력할 수 있는 반면, 후자는 동일한 UI를 사용하지만 사용자 지정 가상 키보드( InputPanel)를 사용합니다. basic.pro 의 다음 스니펫은 qmake 프로젝트가 CONFIG 옵션에 따라 적절한 구현을 선택하도록 설정하는 방법을 보여줍니다:

!qtConfig(vkb-desktop) {
    DEFINES += MAIN_QML=\\\"basic-b2qt.qml\\\"
} else {
    DEFINES += MAIN_QML=\\\"Basic.qml\\\"
}

이 예제에서는 .qml 파일을 로드하기 전에 QT_IM_MODULE 환경 변수를 설정하여 가상 키보드를 활성화합니다:

#include <QQuickView>
#include <QGuiApplication>
#include <QQmlEngine>

int main(int argc, char *argv[])
{
    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

    QGuiApplication app(argc, argv);
    QQuickView view(QString("qrc:/%2").arg(MAIN_QML));
    if (view.status() == QQuickView::Error)
        return -1;
    view.setResizeMode(QQuickView::SizeRootObjectToView);

    view.show();

    return app.exec();
}

이 외에도 사용자 정의 TextFieldTextArea 항목을 사용하여 EnterKeyAction 첨부 속성을 사용하여 [ENTER] 키 동작을 구성합니다.

import QtQuick
import QtQuick.Controls
import QtQuick.VirtualKeyboard
import "content"

Rectangle {
    ...
                TextField {
                    width: parent.width
                    placeholderText: "One line field"
                    enterKeyAction: EnterKeyAction.Next
                    onAccepted: passwordField.focus = true
                }
    ...
                TextArea {
                    id: textArea
                    width: parent.width
                    placeholderText: "Multiple line field"
                    height: Math.max(206, implicitHeight)
                }
}

TextFieldTextArea 컨트롤은 enterKeyEnabledenterKeyAction 속성을 사용하여 각각의 Qt Quick Controls 2 유형을 확장합니다. 코드 조각의 TextFieldTextArea 인스턴스는 이러한 속성을 설정하여 기본 동작을 변경할 수 있습니다.

예제 실행하기

에서 예제를 실행하려면 Qt Creator에서 Welcome 모드를 열고 Examples 에서 예제를 선택합니다. 자세한 내용은 예제 빌드 및 실행하기를 참조하세요.

예제 프로젝트 @ code.qt.io

© 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.