简体   繁体   English

在字符串中使用QML属性

[英]Use QML property inside a string

I've this QML object (from this sample ): 我有这个QML对象(来自此示例 ):

Path {
    startX: 50; startY: 50
    PathSvg { path: "L 150 50 L 100 150 z" }
}

Now I want to add an attribute specifying a length, and I want to use it inside the Svg string. 现在,我想添加一个指定长度的属性,并在Svg字符串中使用它。 Something like 就像是

Path {
    startX: 50; startY: 50
    length: 200
    PathSvg { path: "L length 50 L 100 length z" }
}

How can I insert a numeric property inside a string in a QML object? 如何在QML对象的字符串内插入数字属性?

Just do: 做就是了:

Path {
    id: p
    startX: 50; startY: 50
    length: 200
    PathSvg { path: "L " + p.length + " 50 L 100 " + p.length + " z" }
}

The good news is if the length changes, this will reevaluate and update the path string. 好消息是,如果长度发生变化,它将重新评估并更新路径字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM