Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to create a nested Listview
Forum Update on Monday, May 27th 2025

How to create a nested Listview

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 5 Posters 5.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Deqing
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kkrzewniak
      wrote on last edited by
      #2

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

      Me, Grimlock, not "nice dino". ME BASH BRAINS!

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Deqing
          wrote on last edited by
          #4

          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 @

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Milnadar
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Merinas
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Deqing
                wrote on last edited by
                #7

                [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 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved