qt - qml 虚拟键盘 : keyboardDesignWidth and Height

标签 qt qml qt-quick qtvirtualkeyboard

我正在查看虚拟键盘的 QML 样式。键盘设计宽度和高度的目的是什么?我似乎在管理键盘的宽度和高度时遇到了很多麻烦,并且永远无法将其设置为我想要的方式。直接设置keyboardHeight和Width也没有多大帮助。

问题在于组件背景大小是在幕后以某种方式计算的。因此,即使我拥有我想要的键盘按钮和大小,无关的背景也会覆盖我的一些其他控件,并且很难对键盘的大小进行细粒度控制。

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

最佳答案

引用 Documentation

The keyboard size is automatically calculated from the available width; that is, the keyboard maintains the aspect ratio specified by the current style. Therefore the application should only set the width and y coordinates of the InputPanel, and not the height.

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

What is the right way to control the width and size of the virtual keyboard directly?

例如

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

例如

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

那么 keyboardDesignHeight/Width 是怎么回事?好吧,这似乎是键盘的尺寸,当不需要缩放它时:

scaleHint : real
The keyboard style scale hint. This value is determined by dividing keyboardHeight by keyboardDesignHeight. All pixel dimensions must be proportional to this value.
This property is readonly!

因此设置这些不会禁用根据宽度自动调整输入面板的大小。

您可能会使用它们来计算一个比率,并据此设置宽度以达到您想要的高度。

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

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

    }
}

关于qt - qml 虚拟键盘 : keyboardDesignWidth and Height,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46236871/

相关文章:

android - 修复 QML Camera 的帧率并改变它的分辨率

c++ - QtQuick : create component from C++

qt - 在 qt5 的 qtquick 2.0 中渲染自定义 opengl

c++ - 在打开 vsync 的情况下执行 glTexImage2D 时出现奇怪的延迟

linux - Qt错误: c: command not found/qmake could not locate g++ compiler

qt - 如何在 QML 信号中传递 MouseEvent 参数

c++ - Qt/QML : Text with inline QML elements

qt - QtCreator (ubuntu) 中的 C++ Octave 链接错误

c++ - 标签中整数的值(Qt)

android - Qt/QML Android 3rd 方虚拟键盘不适用于 TextInput