InputPanel QML Type
提供虚拟键盘用户界面。更多
Import Statement: | import QtQuick.VirtualKeyboard |
Inherits: |
属性
- active : bool
(since QtQuick.VirtualKeyboard 2.0)
- externalLanguageSwitchEnabled : bool
(since QtQuick.VirtualKeyboard 2.4)
信号
- externalLanguageSwitch(var localeList, int currentIndex)
(since QtQuick.VirtualKeyboard 2.4)
详细说明
键盘尺寸是根据可用宽度自动计算得出的;也就是说,键盘保持当前样式指定的宽高比。因此,应用程序只能设置输入面板的width 和y 坐标,而不能设置height 。
与模块提供的所有其他 QML 类型一样,在使用 InputPanel 之前,必须将QT_IM_MODULE
环境变量设置为qtvirtualkeyboard
。更多信息,请参阅加载插件。
注意: 您的应用程序中只能有一个 InputPanel 实例。面板不会被模式对话框阻挡,但可能会被z 值更高的项目遮挡。
属性文档
active : bool |
该属性反映了输入面板的活动状态。当该属性为true
时,用户应能看到键盘。
该属性在 QtQuick.VirtualKeyboard 2.0 中引入。
externalLanguageSwitchEnabled : bool |
该属性启用外部语言切换机制。当该属性为true
时,虚拟键盘将不显示内置语言弹出窗口,而是发出externalLanguageSwitch 信号。应用程序可以处理该信号,并显示自定义语言选择对话框。
该属性在 QtQuick.VirtualKeyboard 2.4 中引入。
信号文档
当externalLanguageSwitchEnabled 为true
且用户按下语言切换键时,将发出该信号。
它是一个钩子,用于显示自定义语言对话框,而不是虚拟键盘中的内置语言弹出窗口。
localeList 参数包含一系列可供选择的语言名称。要获取有关特定语言的更多信息,请使用Qt.locale() 函数。currentIndex 是localeList 中当前语言的索引。在用户界面中,该项应作为当前项目突出显示。
要选择新语言,请使用VirtualKeyboardSettings.locale 属性。
下面的示例演示了自定义语言对话框的实现:
Dialog { id: languageDialog title: "Select Input Language" modality: Qt.ApplicationModal function show(localeList, currentIndex) { languageListModel.clear() for (var i = 0; i < localeList.length; i++) { languageListModel.append({localeName: localeList[i], displayName: Qt.locale(localeList[i]).nativeLanguageName}) } languageListView.currentIndex = currentIndex languageListView.positionViewAtIndex(currentIndex, ListView.Center) languageDialog.visible = true } contentItem: ListView { id: languageListView model: ListModel { id: languageListModel function selectItem(index) { VirtualKeyboardSettings.locale = languageListModel.get(index).localeName languageDialog.visible = false } } delegate: Item { id: languageListItem width: languageNameTextMetrics.width * 17 height: languageNameTextMetrics.height + languageListLabel.anchors.topMargin + languageListLabel.anchors.bottomMargin Text { id: languageListLabel anchors.left: parent.left anchors.top: parent.top anchors.leftMargin: languageNameTextMetrics.height / 2 anchors.rightMargin: anchors.leftMargin anchors.topMargin: languageNameTextMetrics.height / 3 anchors.bottomMargin: anchors.topMargin text: languageNameFormatter.elidedText color: "#5CAA15" font { weight: Font.Normal pixelSize: 28 } } TextMetrics { id: languageNameTextMetrics font { weight: Font.Normal pixelSize: 28 } text: "X" } TextMetrics { id: languageNameFormatter font { weight: Font.Normal pixelSize: 28 } elide: Text.ElideRight elideWidth: languageListItem.width - languageListLabel.anchors.leftMargin - languageListLabel.anchors.rightMargin text: displayName } MouseArea { anchors.fill: parent hoverEnabled: true onClicked: { if (index === -1) return parent.ListView.view.currentIndex = index parent.ListView.view.model.selectItem(index) } } states: State { name: "current" when: languageListItem.ListView.isCurrentItem PropertyChanges { target: languageListLabel color: "black" } } } } }
然后将声明该对话框:
LanguageDialog { id: languageDialog width: 400 height: 400 }
在应用程序的InputPanel 中,添加以下代码:
InputPanel { id: inputPanel externalLanguageSwitchEnabled: true onExternalLanguageSwitch: languageDialog.show(localeList, currentIndex) // ... }
现在,当按下语言切换键时,将显示自定义对话框。
注意: 相应的处理程序是onExternalLanguageSwitch
。
该信号在 QtQuick.VirtualKeyboard 2.4 中引入。
© 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.