Set common property value in QML such as QSS

大城市里の小女人 提交于 2019-12-05 16:39:53

There is no support for customizing using QSS in QML. But you can use "Style Object" method to set the properties and use them in all your QML files.

In this, you define a Style object in a "Style.qml" file, with properties defining the style. Instantiate in the root component, so it will be available throughout the application.

// Style.qml
QtObject {
    property int textSize: 20
    property color textColor: "green"
}

// root component
Rectangle {
    ...
    Style { id: style }
    ...
}

// in use
Text {
    font.pixelSize: style.textSize
    color: style.textColor
    text: "Hello World"
}

You can find more information here.

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