qml自定义虚拟键盘

1 篇文章 0 订阅

官方文档

传送门
下面是qt官方文档种复制过来的
The virtual keyboard styling system supports built-in styles as well as custom styles. The built-in styles are embedded as Qt Resources into the plugin binary and the custom styles are located in the file system and can be installed without recompiling the virtual keyboard itself.

The selection of the runtime style is affected by an environment variable QT_VIRTUALKEYBOARD_STYLE, which can be set to the name of the built-in style, e.g. “retro”, or any of the custom styles installed into the Styles directory:

$$[QT_INSTALL_QML]/QtQuick/VirtualKeyboard/Styles
In case the environment variable is not set, or contains an invalid style name, the virtual keyboard falls back in the default built-in style.

Adding Custom Styles
The process of creating a new style begins by creating a new subdirectory for the style in a QML import path under the URL-based directory structure QtQuick/VirtualKeyboard/Styles/. See QML Import Path for information about QML import paths. The directory name can not contain spaces or special characters other than underscore. Also, the directory name can not be the same as one of the built-in style, which currently includes “default” and “retro”.

A good starting point for creating a new style is to use an existing built-in style as a template and edit it. You can find the built-in styles from the virtual keyboard sources directory src/virtualkeyboard/content/styles. Copy one of the directories containing a built-in style into the Styles directory and rename it to “test”. The directory structure should now be as follows:

test/default_style.qrc
test/style.qml
test/images
test/images/backspace.png
test/images/check.png
test/images/enter.png
test/images/globe.png
test/images/hidekeyboard.png
test/images/search.png
test/images/shift.png
The QRC configuration file, which is unnecessary in this case, can be safely removed.

Note: The style.qml file should not be renamed, or otherwise the virtual keyboard cannot load the style.

Next, open the style.qml in your favorite editor and set the resourcePrefix property to an empty string. The resource prefix is not needed as the resources are contained in the same directory as the style.qml file.

Also, to make it more obvious to see that the custom style is actually being loaded and used, set the keyboard background to a different color:

keyboardBackground: Rectangle {
color: “gray”
}
The final step is to run the example application with your custom style:

QT_VIRTUALKEYBOARD_STYLE=test virtualkeyboard

文档内容说明

根据文档说明首先找qt源码Src\qtvirtualkeyboard\src\virtualkeyboard\content\styles中的两个文件夹(源码路径必须要在安装的时候勾选了src选项才会有)default和retro文件夹;将default拷贝到qt编译版本目录中的qml\QtQuick\VirtualKeyboard\Styles文件夹中(qt编译版本文件夹根据自己编译的程序自适应,比如windows系统64位程序就是qt安装目录/qt版本/msvc2017_64目录)。
然后将default文件夹名称改为test(这个随便定义)main.cpp中加入

	   qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
       qputenv("QT_VIRTUALKEYBOARD_STYLE","test");

要注意的是第二句的test位置的内容必须和上文中修改的文件夹名字一致,否则系统会使用默认的风格。
然后我们修改test文件夹中的style.qml文件,将readonly property string resourcePrefix:后面的内容改为"";然后具体的格式就看我们自己发挥啦。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值