您的位置:首页 > 编程语言 > Qt开发

arm开发板上使用qt5.8虚拟键盘(支持中文)

2017-11-09 09:02 3019 查看
qt5.8是支持虚拟键盘的,但是不能使用拼音输入中文,但是虚拟键盘库的编译是可配置的。

以下所有过程是qt5.8源码编译、安装完成后实现的。

一、编译支持中文的虚拟键盘库(如果不需要中文,这一步可以省略)

1.进入拼音的源码目录:

cd ./qt-everywhere-opensource-src-5.8.0/qtvirtualkeyboard/src/virtualkeyboard/3rdparty/pinyin

2.qmake pinyin.pro,生成Makefile;

3.make,生成拼音的库;

4.vim qt-everywhere-opensource-src-5.8.0/qtvirtualkeyboard/src/virtualkeyboard/virtualkeyboard.pro,在Pro文件中对应的位置加入标记红色的内容:

          TARGET  = qtvirtualkeyboardplugin
  DATAPATH = $$[QT_INSTALL_DATA]/qtvirtualkeyboard

 QMAKE_DOCS = $$PWD/doc/qtvirtualkeyboard.qdocconf
include(doc/doc.pri)

QT += qml quick gui gui-private core-private
   CONFIG += lang-zh_CN 

   CONFIG += lang-en_GB

win32 {

    CONFIG += no-pkg-config

    QMAKE_TARGET_PRODUCT = "Qt Virtual Keyboard (Qt $$QT_VERSION)"

    QMAKE_TARGET_DESCRIPTION = "Virtual Keyboard for Qt."
}

5.cd qt-everywhere-opensource-src-5.8.0/qtvirtualkeyboard

        6.qmake qtvirtualkeyboard.pro

        7.make

8.sudo make install

9.将qt5.8的所有安装目录文件重新拷入开发板;

二、在程序中使用虚拟键盘

1.在程序的pro文件中加入以下内容:

static{
QTPLUGIN+=qtvirtualkeyboardplugin
QT+=svg
}
2.在main函数中加入一条语句:

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

以上就完成了虚拟键盘的使用,在lineEdit控件上点击,键盘就会弹出来。

弹出的虚拟键盘是一个新的窗口,会遮挡住原有的窗口,暂时未解决该问题。
官网是这样解释的:
The input
panel must be a sibling element next to the application container. It is important not to put the input panel
within the application container,
as it would
then overlap with the contents of the application. Also, the input panel height will be automatically updated
according to the available width; 
the aspect
ratio of the input panel is constant.
还给出了一个实例,但是是QML文本:

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

    }

}

可本人对QML方面的知识也不了解,只能暂时搁置。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息