arm開發板上使用qt5.8虛擬鍵盤(支持中文)

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方面的知識也不瞭解,只能暫時擱置。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章