隐藏Qt虚拟键盘中的按键

5
有没有一种方法可以在不使用自定义布局的情况下隐藏虚拟键盘上的语言选择键?

enter image description here


我不熟悉虚拟键盘,但这听起来像是自定义布局。如果键盘支持更改布局,则应该可以隐藏它。我真的怀疑它支持隐藏特定的按键。 - rbaleksandar
3个回答

3

我通过一个变通方法成功隐藏了语言键:

    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属性定义为“changeLanguageKey”时才起作用,对于早期版本,请在源代码中设置该属性并重新编译。


这个很好用,但不幸的是,hideKeyboardKey没有对象名称或我可以引用的属性。有什么想法如何摆脱它?我导入了自定义样式,所以我可以将其启用属性设置为false,但如果你那样做布局不会自动调整 :( 我觉得他们应该将一个简单的方法集成到键盘中来完成这个任务。 - Rob

1

不行,除非使用自定义布局。

但你可以修改键盘自带的布局。


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
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接