Delegate in another file
-
Hello
I want to make a ListView where I refer the delegate from another file, but it doesn't seem to work.
Is this not possible?
For examplemain.qml
@ListView {
model: myModel
delegate: MyDelegate
}
@
MyDelegate.qml
@Component{
//Populate the list with myModel
}@Thanks in advance ^^
[Edit: Added @ tags around code -- mlong]
-
Yes it is possible, although I'm not sure whether you should be using Component in the MyDelegate.qml. I don't have a handy example right here and now, but in general it usually works.
-
My example above, returns a reference error. It says that MyDelegate is not defined.
So any ideas about how I can make this work? -
perhaps an include is missing?
I'm back at my machine now, will try to create an example for you.
-
OK as I've said - it works. Both with delegate defining a Component and a plain Rectangle.
Code (both files are in the same directory:
@
// main.qml
import QtQuick 1.1Rectangle {
width: 360
height: 360ListView { anchors.fill: parent model: ListModel { ListElement { entryText: "Bla bla" } ListElement { entryText: "Bla bla 2" } } delegate: MyDeletage {} }
}
@And the delegate:
@
// MyDelegate.qml
import QtQuick 1.1Component { // This is optional. It works with Rectangle, too
Rectangle {
width: 200
height: 100
border.color: "#000000"
border.width: 2Text { anchors.fill: parent text: entryText } }
}
@