仮想キーボードQt Quick
この例では、Qt Quick アプリケーションで仮想キーボードを使用する方法を示します。
この例には2つの実装があります:1つはデスクトッ ププラットフォーム用、もう1つは組み込みプラットフォーム用です。前者のバージョンでは、仮想キーボードを使って複数のテキスト・フィールドにテキストを入力することができ、後者のバージョンでは、同じUIを使いますが、カスタムの仮想キーボードInputPanel 。basic.pro
。次のスニペットは、CONFIGオプションに基づいて適切な実装を選択するために、qmakeプロジェクトがどのようにセットアップされるかを示しています:
!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(); }
これに加えて、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 コントロールは、enterKeyEnabled
とenterKeyAction
プロパティで、それぞれのQt Quick Controls 2タイプを拡張します。スニペット内のTextField とTextArea インスタンスは、これらのプロパティを設定して、デフォルトの動作を変更することができます。
例の実行
からサンプルを実行するには Qt Creatorからサンプルを実行するには、Welcome モードを開き、Examples からサンプルを選択します。詳細については、Building and Running an Exampleを参照してください。
© 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.