Qt5 Virtual Keyboard C++ Integration and Implementation (QWidget)

Qt5 Virtual Keyboard C++ Integration and Implementation


Building Qt Virtual Keyboard
keyboardDesignWidth and Height

I. Download Source Code

Go to the official github to download the required version of the source code:
The version I downloaded is:

II. Settings

  1. Configure the required language
    1). Configured by Qt Creator
    Open the Qt project file and open the left side of the project Projects->Build->Build Steps->qmake->Additional arguments
    Add configuration parameters in Additional arguments:

    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-zh_CN lang-zh_TW"

    Select the desired language as needed, of course, if you simply configure it for all languages, then as the following:

  2. Configure the required language
    2). Configure and generate the makefile directly from the command line.

    /opt/Qt5.10.1/5.10.1/gcc_64/bin/qmake qtvirtualkeyboard.pro -spec linux-g++ 'CONFIG+=lang-all'

    Specify the linux platform with the -spec parameter.

  3. The virtualkeyboard.pro configuration file add the following content:


    The reason for this is because when integrating Chinese language, Japanese, etc. with the language of the three-party library, the generated three-party library will not be found when the qtvirtualkeyboard is finally generated. We only need to add a path to solve this problem.

III. C++ integration

In order to use Qt Virtual Keyboard in the traditional QWidget program (corresponding to QML), we only need to add the following code at the entry of the program:

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

Finally, the program looks like this

int main(int argc, char *argv[])
    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

    QApplication a(argc, argv);
    MainWindow w;

    return a.exec();

IV. Customize keyboard size and location

We need to change the InputPanel.qml file

Item {
    id: inputPanel

    property int screenHeight: Screen.desktopAvailableHeight; 
    anchors.fill: parent;

    Keyboard {
        id: keyboard

        anchors.horizontalCenter: parent.horizontalCenter
        width: Screen.desktopAvailableWidth * 2 / 3
        y: getInputY()

        function getInputY(){
            return 0

The sample code is shown above, defining the horizontal center position and width of the keyboard. The vertical position of the keyboard is set by y and returned by the getInputY() function. I does not give a concrete implementation. A more general idea can be according to the position of the input box to adapt the position of the keyboard, of course, this also needs to change the c++ code of the qtvirtualkeyboard related files, I will not be described here.

V. More Qt5 Virtual Keyboard Settings

  1. Qt5 Virtual Keyboard C ++ Integration and Implementation II (Adaptive Position)
  2. Qt5 Virtual Keyboard C ++ Integration and Implementation III (Solving the Problem of Modal Dialog Keyboard Invalidation)
0 0 votes
Article Rating
赞(1) 打赏
未经允许不得转载:iemblog » Qt5 Virtual Keyboard C++ Integration and Implementation (QWidget)
Notify of

Inline Feedbacks
View all comments
免责声明:本站大部分下载资源收集于网络,只做学习和交流使用,版权归原作者所有,请在下载后24小时之内自觉删除,若作商业用途,请购买正版,由于未及时购买和付费发生的侵权行为,与本站无关。本站发布的内容若侵犯到您的权益,请联系站长删除,我们将及时处理! Disclaimer: Most of the download resources on this site are collected on the Internet, and are only used for learning and communication. The copyright belongs to the original author. Please consciously delete within 24 hours after downloading. If you use it for commercial purposes, please purchase the original version. If the content posted on this site violates your rights, please contact us to delete it, and we will deal with it in time!

联系我们 Contact us




Would love your thoughts, please comment.x