从Qt虚拟键盘隐藏密钥

时间:2017-03-16 12:24:59

标签: qt qml qtvirtualkeyboard

有没有办法在不使用自定义布局的情况下从虚拟键盘隐藏语言选择键?

enter image description here

3 个答案:

答案 0 :(得分:2)

我能够通过解决方法隐藏语言键:

    property var keyboardLayout: inputPanel.keyboard.layout


    function findChildByProperty(parent, propertyName, propertyValue, compareCb) {
        var obj = null
        if (parent === null)
            return null
        var children = parent.children
        for (var i = 0; i < children.length; i++) {
            obj = children[i]
            if (obj.hasOwnProperty(propertyName)) {
                if (compareCb !== null) {
                    if (compareCb(obj[propertyName], propertyValue))
                        break
                } else if (obj[propertyName] === propertyValue) {
                    break
                }
            }
            obj = findChildByProperty(obj, propertyName, propertyValue, compareCb)
            if (obj)
                break
        }
        return obj
    }



    onKeyboardLayoutChanged: {
        if(keyboardLayout!=""){
            var ChangeLanguageKey= findChildByProperty(inputPanel.keyboard, "objectName", "changeLanguageKey", null)
            if(ChangeLanguageKey){
                ChangeLanguageKey.visible=false
            }
        }
    }


    InputPanel {
        id: inputPanel
        z: 99
        y: parent.height
        anchors.left: parent.left
        anchors.right: parent.right




        states: State {
            name: "visible"

            when: inputPanel.active
            PropertyChanges {
                target: inputPanel
                y: parent.height - inputPanel.height
            }
        }
        transitions: Transition {
            from: ""
            to: "visible"
            reversible: true
            ParallelAnimation {
                NumberAnimation {
                    properties: "y"
                    duration: 400
                    easing.type: Easing.InOutBack
                }
            }
        }





        CustomComponents.AutoScroller {

            id:autoscroller

            panelY: inputPanel.y
        }


    }

enter image description here

这仅适用于版本5.9,其中objectname属性使用&#34; changeLanguageKey&#34;定义,对于以前的版本,在源代码中设置属性并重新编译。

答案 1 :(得分:1)

不,不是没有使用自定义布局。

您可以随时修改键盘附带的布局。

答案 2 :(得分:1)

我可以用这个技巧隐藏 hideKeyboard 键。我基本上试图获得表情符号键的引用,从而能够禁用下一个键,即 hideKeyboard 键。

function disableKey(parent, objectText) 
{

   var obj = null
   if (parent === null)
        return null
   var children = parent.children       
   for (var i = 0; i < children.length; i++) {
       obj = children[i]
       if (obj.text === objectText && obj.toString().substring(0, 7) === "BaseKey") {
           console.log("Disabling symbols. " + obj.text)
           obj.enabled = false
       }
       else if(obj.displayText === "HWR"){
            console.log("Disabling Handwriting mode button." + obj.displayText + " " + objectText)
            obj.visible = false
       }          
       else if(obj.text === ":-)" && obj.toString().substring(0, 7) === "BaseKey"){
           console.log("Disabling hidekeyboard key." + obj.text)
           children[i+1].visible = false
       } 
   obj = disableKey(obj, objectText)
       if (obj)
           break
   }
   return obj
}