qml desktop components scaling

ⅰ亾dé卋堺 提交于 2019-12-11 03:46:51

问题


I want to create a user interface qtquick2 that can be scaled and includes some desktop components. As mentioned in this blogpost the default rendering for qml/qtquick2 should use distance fields and not native text rendering. I tried to scale qt quick controls. The result is rather disappointing. I was testing on ubuntu 64 and qt-5.1.1. The text on the controls is looking bad but all text in standard qml elements (Text/TextEdit) is looking good when scaled.

This leads me to think that native rendering is the default now for desktop components. Can this be turned of?


回答1:


Setting render types of Qt Quick Controls will be available in Qt 5.2 using styles, e.g. in TextArea:

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

Supported render types are:

  • Text.QtRendering
  • Text.NativeRendering (default)

See TextArea.qml, TextAreaStyle.qml.

For Button and ButtonStyle there is no public interface to set the render type directly in Qt 5.2. But what you can do, is overwrite the label with your own text component:

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
            }
        }
    }
}

This code is inspired by the default label component of ButtonStyle.qml, modified and untested.




回答2:


I don't think you can change text rendering in Qt Components since they are explicitly made for the use in desktop applications.

In TextArea for example there is no renderType like in TextEdit.

On the QtDesktopComponents page I another hint:

You have to change QGuiApplication to a QApplication. This is because the components rely on certain widget-specific classes such as QStyle to do native rendering.



来源:https://stackoverflow.com/questions/20311318/qml-desktop-components-scaling

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!