如何访问QmlStyling嵌套QtObjects?

时间:2016-08-08 07:36:32

标签: qt qml

我想在另一个Qml文件中访问嵌套的QtObject。 QmlStyling Nesting QtObjects

subDir / Style.qml文件

pragma Singleton
import QtQuick 2.0

QtObject {

property int textSize: 40
property color textColor: "green"
property color rectColor: "red"

property QtObject window: QtObject {
    property color background: "white";
}

property QtObject border: QtObject {

    property QtObject width: QtObject {
        property int normal: 1;
        property int big: 3;
    }

    property QtObject color: QtObject {
        property color normal: "gray";
        property color focus: "blue";
        property color disabled: "red";
    }
}
}

我想在Screen1.qml中访问它

import QtQuick 2.0

import QtQuick.Controls 1.4

import "subDir" 1.0

Item 
{
id: rootItem
width: 800; height: 600

Rectangle {
    id:myRect
    x: 47; y: 61
    width: 706; height: 478
    color: Style.rectColor // This works correctly
    //But this below line doesn't
    border.width: Style.border.width.big // I want to access something like this
}
}

在subDir / qmldir文件中:

singleton Style 1.0 Style.qml

qmldir和Style.qml文件位于同一文件夹中(仅供参考)

qml.qrc文件:

<RCC>
<qresource prefix="/">
    <file>main.qml</file>
    <file>MainForm.ui.qml</file>
    <file>Screen1.qml</file>
    <file>subDir/qmldir</file>
    <file>subDir/Style.qml</file>
</qresource>

0 个答案:

没有答案