xml-ph-0000@deepl.internal의 가상 키보드 Qt Quick
이 예제는 Qt Quick 애플리케이션에서 가상 키보드를 사용하는 방법을 보여줍니다.

이 예제에는 데스크톱 플랫폼용과 임베디드 플랫폼용, 두 가지 구현 방식이 있습니다. 전자는 가상 키보드를 사용하여 여러 텍스트 필드에 텍스트를 입력할 수 있게 하는 반면, 후자는 동일한 UI를 사용하되 사용자 정의 가상 키보드 InputPanel 를 적용합니다. 다음 코드 조각은 CONFIG 옵션을 기반으로 적절한 구현 방식을 선택하도록 프로젝트를 설정하는 방법을 보여줍니다:
- qmake에서 (
basic.pro):!qtConfig(vkb-desktop) { DEFINES += MAIN_QML=\\\"basic-b2qt.qml\\\" } else { DEFINES += MAIN_QML=\\\"Basic.qml\\\" } - CMake에서 (
CMakeLists.txt):if(NOT QT_FEATURE_vkb_desktop) target_compile_definitions(basic PUBLIC MAIN_QML="basic-b2qt.qml" ) endif() ... if(QT_FEATURE_vkb_desktop) target_compile_definitions(basic PUBLIC MAIN_QML="Basic.qml" ) endif()
이 예제에서는 .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();
}이 외에도, 사용자 정의 TextField 및 TextArea 항목을 사용하여 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)
}
}TextField 및 TextArea 컨트롤은 각각 Qt Quick Controls 2 유형을 확장하여 enterKeyEnabled 및 enterKeyAction 속성을 제공합니다. 코드 조각에 있는 TextField 및 TextArea 인스턴스는 이러한 속성을 설정하여 기본 동작을 변경할 수 있습니다.
예제 실행
다음 경로에서 예제를 실행할 수 있습니다.
- Qt Creator
Welcome 모드를 열고 Examples 에서 예제를 선택하십시오. 자세한 내용은 Qt Creator: 튜토리얼: 빌드 및 실행을 참조하십시오.
- Qt Extension for Visual Studio Code
Command Palette 에서 Qt: Open Qt examples 명령을 실행하고 목록에서 예제를 선택합니다. 자세한 내용은 Qt Extension for Visual Studio Code: 튜토리얼: 빌드 및 실행을 참조하십시오.
© 2026 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.