How to create a nested Listview
-
wrote on 26 Apr 2011, 15:36 last edited by
Any idea how to create a nested List view?
I have several folders to display. When user click a folder's name, all files under that folder should be displayed as a list.
Ideally it also supports drag and drop between different folders.
-
wrote on 26 Apr 2011, 15:47 last edited by
It sounds to me like a tree model. Perhaps QFileSystemModel.
-
wrote on 26 Apr 2011, 16:16 last edited by
One of possible solution of treeview creation is nested listviews. You can declare ListView in your delegate and use it.
-
wrote on 27 Apr 2011, 05:49 last edited by
Looks like it is not easy to do.
For example, I can list folders by:
@
Item {
width: 800; height: 600ListModel { id: folderList ListElement { name: "folder1" } ListElement { name: "folder2" } } Component { id: folderDelegate Rectangle { width: parent.width; height: text.height*1.5; color: "lightgreen" Text { id: text; text: name } } } ListView{ id: listView anchors.fill: parent model: folderList delegate: folderDelegate }
}
@But where should I put file names of those folder to?
Tried putting into list model but seeing following error
@ListElement: cannot contain nested elements @ -
wrote on 27 Apr 2011, 08:26 last edited by
How about to create new listModel for every folder, and to keep them invisible until not pressed needed item?
Are there any nested folders in folders which you click on? Or just files? -
wrote on 27 Apr 2011, 09:17 last edited by
You can do it that way
@import QtQuick 1.0ListModel
{
ListElement {
a: 10
b:[
ListElement{//},
ListElement{//},
ListElement{//}
]
}
ListElement {
a: "20
b:[
ListElement{//},
ListElement{//},
ListElement{//}
]
}
}
@where b will be a new ListModel.
-
wrote on 27 Apr 2011, 12:29 last edited by
[quote author="Milnadar" date="1303892815"]How about to create new listModel for every folder, and to keep them invisible until not pressed needed item?
Are there any nested folders in folders which you click on? Or just files?[/quote]Indeed in a folder there are possibly subfolders and files. :(
1/7