查看完整版本: [-- 请问怎样的同一个qml 文件中实现自定义的组件重用? --]

QTCN开发网 -> Qt QML开发 -> 请问怎样的同一个qml 文件中实现自定义的组件重用? [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

neeme 2018-01-25 16:50

请问怎样的同一个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.text
        
        Text {
            id: t1
            text: qsTr("line-1")
            font.pixelSize: 20
            anchors.centerIn: parent
            color: "yellow"
        }        
    }


never_forget 2018-01-26 13:35
Repeater ,注意查看文档!

neeme 2018-01-27 09:10
never_forget:Repeater ,注意查看文档! (2018-01-26 13:35) 

Repeater, 只能硬性重复,不能改变任何东西。注意查看问题!

never_forget 2018-01-29 19:09
never_forget:Repeater ,注意查看文档! (2018-01-26 13:35) 

通过 model 属性不能改变 text? 你在说啥?

neeme 2018-01-31 10:52
never_forget:通过 model 属性不能改变 text? 你在说啥? (2018-01-29 19:09) 


弄懂了,谢谢你!初学水平有限,不要介意。


查看完整版本: [-- 请问怎样的同一个qml 文件中实现自定义的组件重用? --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled