【问题标题】:qml desktop components scalingqml 桌面组件缩放
【发布时间】:2013-12-01 10:49:49
【问题描述】:

我想创建一个可以缩放并包含一些桌面组件的用户界面 qtquick2。正如blogpost 中提到的,qml/qtquick2 的默认渲染应该使用距离字段而不是原生文本渲染。我试图扩展 qt 快速控件。结果相当令人失望。我在 ubuntu 64 和 qt-5.1.1 上进行测试。控件上的文本看起来很糟糕,但标准 qml 元素 (Text/TextEdit) 中的所有文本在缩放时看起来都很好。

这让我认为原生渲染现在是桌面组件的默认设置。这个可以关闭吗?

【问题讨论】:

    标签: c++ qt qml qtquick2


    【解决方案1】:

    在 Qt 5.2 中可以使用样式设置 Qt Quick Controls 的渲染类型,例如在TextArea:

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

    支持的渲染类型有:

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

    TextArea.qmlTextAreaStyle.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 组件,已修改且未经测试。

    【讨论】:

      【解决方案2】:

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

      例如在TextArea 中没有renderType 就像在TextEdit 中一样。

      QtDesktopComponents 页面上我还有一个提示:

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

      【讨论】:

      • 感谢您的回复。唯一让我觉得文本渲染可以使用距离字段的就是在博客中作为例子来解释。也许这是 QtDesktopComponents 开始时的一个特性,在添加对样式的支持时丢失了。也许我会尝试 git 的旧版本,看看它是否更适合我的需求。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-01
      • 2023-01-02
      • 2022-01-25
      • 1970-01-01
      • 2019-07-10
      相关资源
      最近更新 更多