Solved 请问怎样的同一个qml 文件中实现自定义的组件重用?
-
大家好:
如下 tmp_01 要实现10个, 如果重复10代码感觉很难看,又不想独立一个文件放tmp_01 。 10个tmp_01,都一样, 但要能改变 text ( property alias text: t1.text).
请问怎样实现? 谢谢!Item {
id: tmp_01
width: parent.width
height: 100
property alias text: t1.textText { id: t1 text: qsTr("line-1") font.pixelSize: 20 anchors.centerIn: parent color: "yellow" } }
-
@neeme 你好. 尝试一下,下面组件加载的方法
import QtQuick 2.0 Item { width: 100; height: 100 Component { id: redSquare Rectangle { color: "red" width: 10 height: 10 } } Loader { sourceComponent: redSquare } Loader { sourceComponent: redSquare; x: 20 } }
-
但我怎样改变 t1.text 的值呢? 因为每个的值都不同