qml虚拟键盘:keyboardDesignWidth和高度

问题描述:

我正在查看虚拟键盘的QML样式。 keyboardDesignWidth和Height的用途是什么?我似乎在管理键盘的宽度和高度方面遇到很多麻烦,无法将其设置为我想要的。直接设置keyboardHeight和Width也没有多大帮助。qml虚拟键盘:keyboardDesignWidth和高度

问题是组件背景大小在某种程度上是在幕后计算的。所以,即使我有我想要的键盘按钮和尺寸,多余的背景也会覆盖我的其他一些控件,并且很难对键盘的尺寸进行精细控制。

直接控制虚拟键盘宽度和大小的正确方法是什么?

要从Documentation

键盘尺寸被自动地从可用宽度计算报价;也就是说,键盘保持当前样式指定的宽高比。因此,应用程序应该只设置InputPanel的宽度和y坐标,而不是高度。

所以如果你想有一个特定的高度,你需要相应地设置宽度。

什么是直接控制虚拟键盘宽度和大小的正确方法?

例如,

InputPanel { 
    anchors.fill: parent 
    anchors.leftMargin: 100 
    anchors.rightMargin: 100 
} 

例如,

InputPanel { 
    anchors.horizontalCenter: parent.horizontalCenter 
    anchors.bottom: parent.bottom 
    width: 30 
} 

那么keyboardDesignHeight/Width的处理是什么?嗯,这似乎是键盘的尺寸,当它是不需要它的规模:

scaleHint:真正
键盘风格的规模提示。该值由keyboardHeight除以keyboardDesignHeight确定。所有像素尺寸必须与此值成比例。
此属性是只读!

所以设定那些不会禁用在宽度的依赖性的输入面板的自动调整大小。

你也许可以用它们来计算一个比例,并从中设定宽度来达到你想要的高度。

也许这个例子可以帮助你理解这个属性:

import QtQuick 2.6 
import QtQuick.Window 2.0 
import QtQuick.Controls 2.0 
import QtQuick.VirtualKeyboard 2.0 

ApplicationWindow { 
    id:appwindow 
    visible: true 
    width: 800 
    height: 600 
    title: qsTr("Test") 


    InputPanel { 
     id: ip 
     anchors.horizontalCenter: parent.horizontalCenter 
     anchors.bottom: parent.bottom 
     width: 800 

     Component.onCompleted: console.log(Object.keys(ip.keyboard.style).sort()) 
    } 

    Slider { 
     id: sl 
     from: 0 
     to: 3000 
    } 

    Binding { 
     target: ip.keyboard.style 
     property: 'keyboardDesignHeight' 
     value: sl.value 

    } 
} 
+0

感谢您的回答。具有很大的意义。所以,如果你想要一个方形键盘,你可以将它们设置为相同的值。 – Luca