QML 虚拟键盘添加新布局
QML Virtual Keyboard Add New Layout
我在 raspberry pi 的 Yocto 项目上使用 qt qml 5.7。我的项目需要土耳其语的虚拟键盘。 QT 虚拟键盘 has no support Turkish language so i want to create my custom layout. I add my project example layout codes from here 作为名称 "myCustomLayout.qml"。
我运行我的虚拟键盘显示功能通过以下代码实现。
import QtQuick 2.5
import QtQuick.VirtualKeyboard 2.1
import QtQuick.Controls 2.0
InputPanel {
id: inputPanel
visible: Qt.inputMethod.visible
height:main.height/4
y:main.height - height
x:main.width/8
width: main.width*6/8
focus: true
}
当我运行虚拟键盘显示功能时,出现的键盘不是我自定义的布局,还是常规的英文键盘布局。如何在我的应用程序中添加我的自定义键盘布局?
如果您使用的是早于 5.9 的 Qt 版本,我认为您必须修补 Qt 虚拟键盘以添加您的自定义布局,然后重新构建它。通过添加您自己的条目来修改 this 文件应该就足够了。例如:
contains(CONFIG, lang-tr.*) {
LAYOUT_FILES += \
content/layouts/tr_TR/main.qml
}
如果您使用的是 Qt 5.9 或更高版本,您可以将 QT_VIRTUALKEYBOARD_LAYOUT_PATH
环境变量设置为自定义样式的路径,如前所述 here:
The virtual keyboard layouts system supports built-in layouts as well as custom layouts. The built-in layouts are embedded as Qt Resources into the plugin binary. Custom layouts are located in the file system, so that they can be installed without recompiling the virtual keyboard itself, or they can be located in a resource file.
The selection of layouts at runtime is affected by the QT_VIRTUALKEYBOARD_LAYOUT_PATH
environment variable.
In case the environment variable is not set, or contains an invalid directory, the virtual keyboard falls back to the default built-in layouts.
To prevent the built-in layouts from being built into the virtual keyboard plugin when using custom layouts, add disable-layouts to the CONFIG qmake variable. For more information, see Advanced Configuration Options.
以模块的源代码为例,this test sets it to "/data/layouts"
。
再举一个例子,假设您的应用程序具有以下目录结构:
C:\dev\temp\untitled
│ main.cpp
│ main.qml
│ resources.qrc
│ untitled.pro
│
└───en_GB
dialpad.qml
digits.qml
handwriting.qml
main.qml
numbers.qml
symbols.qml
您可以将其设置为 C:\dev\temp\untitled
。它希望看到一个或多个文件夹,每个文件夹都以其布局所代表的语言 + 国家/地区代码命名,如 here.
要验证它是否正常工作,您可以将 link 上面的 en_GB
布局复制到您的项目中并进行修改(我将 'Q' 键更改为 'Z').
我在我的计算机(不是 pi)的 yocto 构建路径中找到了 qtvirtualkeyboard 文件。
/build/tmp/work/cortexa7hf-neon-vfpv4-poky-linux-gnueabi/qtvirtualkeyboard/5.7.0+gitAUTOINC+626e78c966-r0/git/
我通过在 content/layouts 路径中复制 en_GB 文件创建了一个新的 tr_TR 布局文件。我更改了 tr_TR main.qml 文件。我通过添加以下行修改了 virtualkeyboard.pro 文件,如 Mitch 的回答。
contains(CONFIG, lang-tr.*) {
LAYOUT_FILES += \
content/layouts/tr_TR/main.qml
}
我还修改了 config.pri 文件。我更改了以下几行:
# Default language
!contains(CONFIG, lang-.*) {
contains(QT_CONFIG, private_tests) { # CI or developer build, use all languages
CONFIG += lang-all
} else {
CONFIG += lang-tr_TR
}
}
# Flag for activating all languages
lang-all: CONFIG += \
# lang-ar_AR \
# lang-da_DK \
# lang-de_DE \
lang-en_GB \
# lang-es_ES \
# lang-fa_FA \
# lang-fi_FI \
# lang-fr_FR \
# lang-hi_IN \
# lang-it_IT \
# lang-ja_JP \
# lang-ko_KR \
# lang-nb_NO \
# lang-pl_PL \
# lang-pt_PT \
# lang-ru_RU \
# lang-sv_SE \
lang-tr_TR \
# lang-zh_CN \
# lang-zh_TW
我将更改后的 git 文件复制到 USB 记忆棒并在 pi 上打开我的文件。我用以下命令重建了 qtvirtualkeyboard:
qmake "CONFIG+=lang-all" qtvirtualkeyboard.pro
make
make install
我终于可以使用我的自定义布局了。
我在 raspberry pi 的 Yocto 项目上使用 qt qml 5.7。我的项目需要土耳其语的虚拟键盘。 QT 虚拟键盘 has no support Turkish language so i want to create my custom layout. I add my project example layout codes from here 作为名称 "myCustomLayout.qml"。
我运行我的虚拟键盘显示功能通过以下代码实现。
import QtQuick 2.5
import QtQuick.VirtualKeyboard 2.1
import QtQuick.Controls 2.0
InputPanel {
id: inputPanel
visible: Qt.inputMethod.visible
height:main.height/4
y:main.height - height
x:main.width/8
width: main.width*6/8
focus: true
}
当我运行虚拟键盘显示功能时,出现的键盘不是我自定义的布局,还是常规的英文键盘布局。如何在我的应用程序中添加我的自定义键盘布局?
如果您使用的是早于 5.9 的 Qt 版本,我认为您必须修补 Qt 虚拟键盘以添加您的自定义布局,然后重新构建它。通过添加您自己的条目来修改 this 文件应该就足够了。例如:
contains(CONFIG, lang-tr.*) {
LAYOUT_FILES += \
content/layouts/tr_TR/main.qml
}
如果您使用的是 Qt 5.9 或更高版本,您可以将 QT_VIRTUALKEYBOARD_LAYOUT_PATH
环境变量设置为自定义样式的路径,如前所述 here:
The virtual keyboard layouts system supports built-in layouts as well as custom layouts. The built-in layouts are embedded as Qt Resources into the plugin binary. Custom layouts are located in the file system, so that they can be installed without recompiling the virtual keyboard itself, or they can be located in a resource file.
The selection of layouts at runtime is affected by the
QT_VIRTUALKEYBOARD_LAYOUT_PATH
environment variable.In case the environment variable is not set, or contains an invalid directory, the virtual keyboard falls back to the default built-in layouts.
To prevent the built-in layouts from being built into the virtual keyboard plugin when using custom layouts, add disable-layouts to the CONFIG qmake variable. For more information, see Advanced Configuration Options.
以模块的源代码为例,this test sets it to "/data/layouts"
。
再举一个例子,假设您的应用程序具有以下目录结构:
C:\dev\temp\untitled
│ main.cpp
│ main.qml
│ resources.qrc
│ untitled.pro
│
└───en_GB
dialpad.qml
digits.qml
handwriting.qml
main.qml
numbers.qml
symbols.qml
您可以将其设置为 C:\dev\temp\untitled
。它希望看到一个或多个文件夹,每个文件夹都以其布局所代表的语言 + 国家/地区代码命名,如 here.
要验证它是否正常工作,您可以将 link 上面的 en_GB
布局复制到您的项目中并进行修改(我将 'Q' 键更改为 'Z').
我在我的计算机(不是 pi)的 yocto 构建路径中找到了 qtvirtualkeyboard 文件。
/build/tmp/work/cortexa7hf-neon-vfpv4-poky-linux-gnueabi/qtvirtualkeyboard/5.7.0+gitAUTOINC+626e78c966-r0/git/
我通过在 content/layouts 路径中复制 en_GB 文件创建了一个新的 tr_TR 布局文件。我更改了 tr_TR main.qml 文件。我通过添加以下行修改了 virtualkeyboard.pro 文件,如 Mitch 的回答。
contains(CONFIG, lang-tr.*) {
LAYOUT_FILES += \
content/layouts/tr_TR/main.qml
}
我还修改了 config.pri 文件。我更改了以下几行:
# Default language
!contains(CONFIG, lang-.*) {
contains(QT_CONFIG, private_tests) { # CI or developer build, use all languages
CONFIG += lang-all
} else {
CONFIG += lang-tr_TR
}
}
# Flag for activating all languages
lang-all: CONFIG += \
# lang-ar_AR \
# lang-da_DK \
# lang-de_DE \
lang-en_GB \
# lang-es_ES \
# lang-fa_FA \
# lang-fi_FI \
# lang-fr_FR \
# lang-hi_IN \
# lang-it_IT \
# lang-ja_JP \
# lang-ko_KR \
# lang-nb_NO \
# lang-pl_PL \
# lang-pt_PT \
# lang-ru_RU \
# lang-sv_SE \
lang-tr_TR \
# lang-zh_CN \
# lang-zh_TW
我将更改后的 git 文件复制到 USB 记忆棒并在 pi 上打开我的文件。我用以下命令重建了 qtvirtualkeyboard:
qmake "CONFIG+=lang-all" qtvirtualkeyboard.pro
make
make install
我终于可以使用我的自定义布局了。