How to create a nested Listview



  • 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.



  • It sounds to me like a tree model. Perhaps QFileSystemModel.



  • One of possible solution of treeview creation is nested listviews. You can declare ListView in your delegate and use it.



  • Looks like it is not easy to do.

    For example, I can list folders by:
    @
    Item {
    width: 800; height: 600

    ListModel {
        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 @



  • 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?



  • You can do it that way
    @import QtQuick 1.0

    ListModel
    {
    ListElement {
    a: 10
    b:[
    ListElement{//},
    ListElement{/
    /},
    ListElement{//}
    ]
    }
    ListElement {
    a: "20
    b:[
    ListElement{/
    /},
    ListElement{//},
    ListElement{/
    /}
    ]
    }
    }
    @

    where b will be a new ListModel.



  • [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. :(


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.