qml桌面组件扩展

qml desktop components scaling

本文关键字:扩展 组件 桌面 qml      更新时间:2023-10-16

我想创建一个可以缩放并包含一些桌面组件的用户界面qtquick2。正如这篇博客文章中提到的,qml/qtquick2的默认呈现应该使用距离字段,而不是本地文本呈现。我试着缩放qt快速控制。结果相当令人失望。我在测试ubuntu 64和qt-5.1.1。控件上的文本看起来很糟糕,但标准qml元素(text/TextEdit)中的所有文本在缩放时看起来都很好。

这让我认为原生渲染现在是桌面组件的默认渲染。这个能打开吗?

在Qt 5.2中将使用样式(例如TextArea:)设置Qt Quick Controls的渲染类型

TextArea {
    /* ... */
    style: TextAreaStyle {
        renderType: Text.QtRendering
    }
}

支持的渲染类型有:

  • Text.QtRendering
  • Text.NativeRendering(默认)

参见TextArea.qml、TextAreaStyle.qml.

对于ButtonButtonStyle,没有公共接口可以直接在Qt 5.2中设置渲染类型。但你可以做的是用你自己的文本组件覆盖label

Button {
    id: theButton
    /* ... */
    style: ButtonStyle {
        label: Item {
        implicitWidth: row.implicitWidth
        implicitHeight: row.implicitHeight
        property var __syspal: SystemPalette {
            colorGroup: theButton.enabled ?
                        SystemPalette.Active : SystemPalette.Disabled
        }
        Row {
            id: row
            anchors.centerIn: parent
            spacing: 2
            Image {
                source: theButton.iconSource
                anchors.verticalCenter: parent.verticalCenter
            }
            Text {
                renderType: Text.NativeRendering /* Change me */
                anchors.verticalCenter: parent.verticalCenter
                text: theButton.text
                color: __syspal.text
            }
        }
    }
}

此代码的灵感来自ButtonStyle.qml的默认label组件,该组件经过修改且未经测试。

我不认为您可以更改Qt组件中的文本呈现,因为它们是为桌面应用程序明确设计的。

例如,在TextArea中,没有像TextEdit中那样的renderType

在QtDesktopComponents页面上,我看到了另一个提示:

您必须将QGuiApplication更改为QApplication。这是因为组件依赖于某些特定于小部件的类(如QStyle)来进行本机渲染。