简体   繁体   中英

Use QML property inside a string

I've this QML object (from this sample ):

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. 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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