将连接添加到ListView的委托

时间:2015-04-30 13:54:39

标签: listview delegates qml qt5

我在qml文件中声明了一个ListView(由其他人制作)。此ListView已有一个委托,也在该文件中声明。

在一个单独的文件中,我正在尝试使用该组件并向该列表中的每一行添加行为(Connections和Binding),而不修改第一个文件(布局)。

这可能吗? 基本上,我试图(完全)将逻辑与布局分开。

编辑1 - 代码

main.qml:

Rectangle {
    width: 360
    height: 360

    MyList {
        id : list
        model: ListModel {
            ListElement {
                name: "Bill Smith"
            }
            ListElement {
                name: "John Brown"
            }
            ListElement {
                name: "Sam Wise"
            }
        }
    }    
    //here I want to add behaviour to each item in the list
}

MyList.qml

Item {
    property alias list: myList
    property alias model: myList.model

    ListView {
        id : myList
        delegate : MyDelegate{}
        height : 500
    }

}

MyDelegate.qml

Rectangle {
    id : myDelegate

    property alias mouseArea : mouseArea
    property alias label : label.text

    width : 100
    height : 100
    color : "#C0FFEE"

    MouseArea {
        id : mouseArea
    }
    Text {
        id : label
    }
}

问候!

0 个答案:

没有答案
相关问题