如何控制qt自带的虚拟键盘?

weixin_38049770 2019-09-19 02:18:27
看了网上的帖子,qt5.7以上自带虚拟键盘,只需要在main函数增加qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));就可以然后spinbox自动弹出数字虚拟键盘,lineedit弹出全键盘的虚拟键盘。请教一下,如何在程序中控制是数字还是全键盘的虚拟键盘,如何控制把虚拟键盘关闭,如何控制当前是英文还是中文输入,以及显示位置。
...全文
3264 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
DreamLife. 2022-03-25
  • 打赏
  • 举报
回复 1

22年了,现在有没有好点的方法

m0_50013887 2022-05-25
  • 举报
回复
@DreamLife. 有的
  • 举报
回复
@m0_50013887 什么好方法
逸水天 2019-12-05
  • 打赏
  • 举报
回复
设置输入模式:lineedit有个setInputMethodHints(Qt::ImhPreferLowercase);方法,其中Qt::ImhDigitsOnly就是纯数字键。可查看
enum InputMethodHint枚举。测试使用什么输入方法。
weixin_38050751 2019-09-19
  • 打赏
  • 举报
回复
我用了qt5.8怎么不行呢?
weixin_38069570 2019-09-19
  • 打赏
  • 举报
回复
我的5.9.1也不行,在QML中也无法使用,import后提示未安装,但实际上是安装了的,相应文件夹中可以找到文件。请楼主说说怎么用的,只要在main中包含设置环境变量的这句就可以了吗?
weixin_38073387 2019-09-19
  • 打赏
  • 举报
回复
图片:key.png
weixin_38076559 2019-09-19
  • 打赏
  • 举报
回复
默认的安装 只有英文,中文或者其他文字需要重新编译 键盘 源代码进行安装 键盘有两种,一种是出现在屏幕上,一种是内嵌到qml组件里边,图里的就是嵌入组件的。嵌入的键盘只能设置width度,高度会随着宽度自动变化。键盘的控制 是设置在 输入控件里的,里边有属性设置键盘出现模式。打开或者隐藏键盘有qt的全局属性,可以自己去帮助里边搜索!
weixin_38091394 2019-09-19
  • 打赏
  • 举报
回复
我总结的:1. Before using qtvirtualkeyboard, you should know:1.1 Project directory: D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard1.2 Default build directory: D:\Qt\Qt5.9.0\5.9\Src\build-qtvirtualkeyboard-Desktop_Qt_5_9_0_MinGW_32bit-Debug1.3 layouts directory: D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\content\layouts,    A language+country has a corresponding sub-directory. The qml types inherit from KeyboardLayout or KeyboardLayoutLoader.     They define the layout of the keys.1.4 styles directory: D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\content\styles    A style has a corresponding sub-directory. The qml type inherits from KeyboardStyle.    They define the UI style, such as background images, text fonts and colors.1.5 Sample project directory: D:\Qt\Qt5.9.0\Examples\Qt-5.9\virtualkeyboard2. Build qtvirtualkeyboard2.1 Open project D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\qtvirtualkeyboard.pro in qtcreator.2.2 Add CONFIG += lang-all(or languages we need) in file D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\virtualkeyboard.pro2.3 Add make install to build steps.2.4 Build projects src\openwnn, src\pinyin, src\tcime firstly.2.5 Build the whole project.3. Using qtvirtualkeyboard3.1 In the main() function: qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));    or, $ QT_IM_MODULE=qtvirtualkeyboard myapp3.2 In the main() function: qputenv("QT_VIRTUALKEYBOARD_STYLE", QByteArray("retro"));     Or, Component.onCompleted: VirtualKeyboardSettings.styleName = "retro";3.3 Add the following lines to your .pro file    static {        QT += svg        QTPLUGIN += qtvirtualkeyboardplugin    }3.3 Create InputPanel(Otherwise the virtual keyboard will be shown at the bottom of screen)  import QtQuick 2.0  import QtQuick.VirtualKeyboard 2.1  Item {      id: root      Item {          id: appContainer          anchors.left: parent.left          anchors.top: parent.top          anchors.right: parent.right          anchors.bottom: inputPanel.top          ...      }      InputPanel {          id: inputPanel          y: Qt.inputMethod.visible ? parent.height - inputPanel.height : parent.height          anchors.left: parent.left          anchors.right: parent.right      }  }  3.4 Change VirtualKeyboardSettings.locale, and current language will change correspondingly.3.5 Property VirtualKeyboardSettings.activeLocales can be used to limit the list of available languages in the application lifetime.4. Customize style4.1 Create a directory, vss for example, in D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\content\styles\;4.2 Copy all files in D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\content\styles\retro to vss, change the images files and modify style.qml;4.2 Add following lines to file D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\virtualkeyboard.pro    RESOURCES += \        content/styles/vss/vss_style.qrc \            OTHER_FILES += \        content/styles/vss/*.qml \                4.3 Add following lines to style.qml to make a language selecting popup list    languagePopupListEnabled: true        languageListDelegate: SelectionListItem {        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 {                family: fontFamily                weight: Font.Normal                pixelSize: 44 * scaleHint            }        }        TextMetrics {            id: languageNameTextMetrics            font {                family: fontFamily                weight: Font.Normal                pixelSize: 44 * scaleHint            }            text: "X"        }        TextMetrics {            id: languageNameFormatter            font {                family: fontFamily                weight: Font.Normal                pixelSize: 44 * scaleHint            }            elide: Text.ElideRight            elideWidth: languageListItem.width - languageListLabel.anchors.leftMargin - languageListLabel.anchors.rightMargin            text: displayName        }        states: State {            name: "current"            when: languageListItem.ListView.isCurrentItem            PropertyChanges {                target: languageListLabel                color: "black"            }        }    }    languageListBackground: Rectangle {        color: "white"        border {            width: 1            color: "#929495"        }    }    languageListAdd: Transition {        NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 200 }    }    languageListRemove: Transition {        NumberAnimation { property: "opacity"; to: 0; duration: 200 }    }
weixin_38096807 2019-09-19
  • 打赏
  • 举报
回复
我想加几种语言的layout上去,比如Czech,哪里能找到标准键盘布局呢?
weixin_38107096 2019-09-19
  • 打赏
  • 举报
回复
大神,求指导一下,怎样更改中文输入法备选词字体的大小?小弟跪拜!
wty1121 2022-02-22
  • 举报
回复
@weixin_38107096 怎样在开发板上弹出自带的虚拟键盘呢

435

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧