gpt4 book ai didi

qt - QML封装不新建文件

转载 作者:行者123 更新时间:2023-12-04 13:09:13 28 4
gpt4 key购买 nike

让我们考虑以下示例:

ColumnLayout
{
spacing: 10
Label { color: "green"; text: "one text" }
Label { color: "green"; text: "another text" }
Label { color: "green"; text: "some text" }
}

创建一个类型会很棒。可以创建一个文件 GreenLabel.qml

Label { color: "green" }

然后做这样的事情:

ColumnLayout
{
spacing: 10
GreenLabel { text: "one text" }
GreenLabel { text: "another text" }
GreenLabel { text: "some text" }
}

这可以在不创建另一个文件的情况下完成吗?

最佳答案

这是不可能的。充其量,您可以在 Component 元素内定义一个新类型,然后使用 Loader 或手动动态实例化从类型原型(prototype)创建对象。

关于qt - QML封装不新建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32530548/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com