• 22914阅读
  • 8回复

[提问]如何控制qt自带的虚拟键盘? [复制链接]

上一主题 下一主题
离线wfwjp
 

只看楼主 倒序阅读 楼主  发表于: 2017-07-17
看了网上的帖子,qt5.7以上自带虚拟键盘,只需要在main函数增加qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));就可以
然后spinbox自动弹出数字虚拟键盘,lineedit弹出全键盘的虚拟键盘。
请教一下,如何在程序中控制是数字还是全键盘的虚拟键盘,如何控制把虚拟键盘关闭,如何控制当前是英文还是中文输入,以及显示位置。


离线lsyzsl

只看该作者 1楼 发表于: 2017-07-19
我用了qt5.8怎么不行呢?
离线potter_tang

只看该作者 2楼 发表于: 2017-07-28
我的5.9.1也不行,在QML中也无法使用,import后提示未安装,但实际上是安装了的,相应文件夹中可以找到文件。请楼主说说怎么用的,只要在main中包含设置环境变量的这句就可以了吗?
离线angelus

只看该作者 3楼 发表于: 2017-07-28
离线angelus

只看该作者 4楼 发表于: 2017-07-28
默认的安装 只有英文,中文或者其他文字需要重新编译 键盘 源代码进行安装

键盘有两种,一种是出现在屏幕上,一种是内嵌到qml组件里边,图里的就是嵌入组件的。
嵌入的键盘只能设置width度,高度会随着宽度自动变化。

键盘的控制 是设置在 输入控件里的,里边有属性设置键盘出现模式。
打开或者隐藏键盘有qt的全局属性,可以自己去帮助里边搜索!
离线pitot

只看该作者 5楼 发表于: 2017-08-07
我总结的:
1. Before using qtvirtualkeyboard, you should know:
1.1 Project directory: D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard

1.2 Default build directory: D:\Qt\Qt5.9.0\5.9\Src\build-qtvirtualkeyboard-Desktop_Qt_5_9_0_MinGW_32bit-Debug

1.3 layouts directory: D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\content\layouts,
    A language+country has a corresponding sub-directory. The qml types inherit from KeyboardLayout or KeyboardLayoutLoader.
    They define the layout of the keys.

1.4 styles directory: D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\content\styles
    A style has a corresponding sub-directory. The qml type inherits from KeyboardStyle.
    They define the UI style, such as background images, text fonts and colors.

1.5 Sample project directory: D:\Qt\Qt5.9.0\Examples\Qt-5.9\virtualkeyboard

2. Build qtvirtualkeyboard
2.1 Open project D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\qtvirtualkeyboard.pro in qtcreator.

2.2 Add CONFIG += lang-all(or languages we need) in file D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\virtualkeyboard.pro

2.3 Add make install to build steps.

2.4 Build projects src\openwnn, src\pinyin, src\tcime firstly.

2.5 Build the whole project.

3. Using qtvirtualkeyboard
3.1 In the main() function: qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
    or, $ QT_IM_MODULE=qtvirtualkeyboard myapp

3.2 In the main() function: qputenv("QT_VIRTUALKEYBOARD_STYLE", QByteArray("retro"));
    Or, Component.onCompleted: VirtualKeyboardSettings.styleName = "retro";

3.3 Add the following lines to your .pro file
    static {
        QT += svg
        QTPLUGIN += qtvirtualkeyboardplugin
    }

3.3 Create InputPanel(Otherwise the virtual keyboard will be shown at the bottom of screen)

  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
      }
  }
  
3.4 Change VirtualKeyboardSettings.locale, and current language will change correspondingly.
3.5 Property VirtualKeyboardSettings.activeLocales can be used to limit the list of available languages in the application lifetime.


4. Customize style
4.1 Create a directory, vss for example, in D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\content\styles\;

4.2 Copy all files in D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\content\styles\retro to vss, change the images files and modify style.qml;

4.2 Add following lines to file D:\Qt\Qt5.9.0\5.9\Src\qtvirtualkeyboard\src\virtualkeyboard\virtualkeyboard.pro
    RESOURCES += \
        content/styles/vss/vss_style.qrc \
    
    
    OTHER_FILES += \
        content/styles/vss/*.qml \
        
        
4.3 Add following lines to style.qml to make a language selecting popup list
    languagePopupListEnabled: true
    
    languageListDelegate: SelectionListItem {
        id: languageListItem
        width: languageNameTextMetrics.width * 17
        height: languageNameTextMetrics.height + languageListLabel.anchors.topMargin + languageListLabel.anchors.bottomMargin
        Text {
            id: languageListLabel
            anchors.left: parent.left
            anchors.top: parent.top
            anchors.leftMargin: languageNameTextMetrics.height / 2
            anchors.rightMargin: anchors.leftMargin
            anchors.topMargin: languageNameTextMetrics.height / 3
            anchors.bottomMargin: anchors.topMargin
            text: languageNameFormatter.elidedText
            color: "#5CAA15"
            font {
                family: fontFamily
                weight: Font.Normal
                pixelSize: 44 * scaleHint
            }
        }
        TextMetrics {
            id: languageNameTextMetrics
            font {
                family: fontFamily
                weight: Font.Normal
                pixelSize: 44 * scaleHint
            }
            text: "X"
        }
        TextMetrics {
            id: languageNameFormatter
            font {
                family: fontFamily
                weight: Font.Normal
                pixelSize: 44 * scaleHint
            }
            elide: Text.ElideRight
            elideWidth: languageListItem.width - languageListLabel.anchors.leftMargin - languageListLabel.anchors.rightMargin
            text: displayName
        }
        states: State {
            name: "current"
            when: languageListItem.ListView.isCurrentItem
            PropertyChanges {
                target: languageListLabel
                color: "black"
            }
        }
    }

    languageListBackground: Rectangle {
        color: "white"
        border {
            width: 1
            color: "#929495"
        }
    }

    languageListAdd: Transition {
        NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 200 }
    }

    languageListRemove: Transition {
        NumberAnimation { property: "opacity"; to: 0; duration: 200 }
    }
离线pitot

只看该作者 6楼 发表于: 2017-08-07
我想加几种语言的layout上去,比如Czech,哪里能找到标准键盘布局呢?
离线12345654321

只看该作者 7楼 发表于: 2017-09-13
大神,求指导一下,怎样更改中文输入法备选词字体的大小?小弟跪拜!
离线smileymw

只看该作者 8楼 发表于: 2017-10-12
回 potter_tang 的帖子
potter_tang:我的5.9.1也不行,在QML中也无法使用,import后提示未安装,但实际上是安装了的,相应文件夹中可以找到文件。请楼主说说怎么用的,只要在main中包含设置环境变量的这句就可以了吗? (2017-07-28 21:42) 

还需要在相应的exe文件下把有关的dll文件复制进去
在路上
快速回复
限100 字节
 
上一个 下一个