将QtObject文件用于QML中的样式

时间:2018-11-29 08:56:24

标签: qt qml

是否可以使用带有属性的QtObject拥有如下所示的文件,该文件具有全局样式,然后在另一个QML文件上进行访问?

Globals.qml

import QtQuick 2.0

QtObject {
    id:objectCustom
    property int charWidth: 11
property var text: QtObject {
    property bool bold: true
    property int pointSize: 12
    property int languageSize: 14
    property color textColor: "#ffffff"
    property color textColor_top: "#26e400"
    property color textColor2: "#A9A9A9"

    property color textColor_misc: "#afbcfe" // "#0000ff"
    property color textColor_tmr: "#b4fde5" // "#008B8B"
    property color textColor_glb: "#feb5ed" //"#4B0082"
    property color textColor_tsmo:"#f2feb4" // "#FFFF00"
    property color textColor_oth:"#ff9f9f" // "#D2691E"
    property color textColor_zon:"#e8ffae" // "#32CD32"
    property color textColor_iht: "#ffaef2" // "#7B68EE"
    property color textColor_fla: "#ffb7ae" // "#1E90FF"
    property color textColor_cau:"#aeb7ff" // "#800000"

    property color textColor_hovered:"#d8d8d8" // ""
}

property var scrollBar: QtObject {
    property color handler: "#6b6b6b"
}

property var annotations: QtObject {
    property bool bold: true
    property int fontSize: 9
}

property var button: QtObject {
    property int width: 29
    property int height: 29
}

property var menu: QtObject {
    property color bgColor: "#000000"
    property color bgColorHover: "#555555"
    property real bgOpacityHover: 0.6
    property real bgOpacityPress: 1.0
    property color textColor: "#ffffff"
    property real fontSize: 12.0
    property bool fontBold: true

}

property var panel: QtObject{
    property color bgColor: "#000000"
    property int width: 360
    property int width2: 200
}}

编辑:如果我将它包含在main.qml中,

Globals {
    id: globals
}

这样,可以轻松访问所有属性!

0 个答案:

没有答案