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. Using TableView as ListView-delegate
Forum Updated to NodeBB v4.3 + New Features

Using TableView as ListView-delegate

Scheduled Pinned Locked Moved QML and Qt Quick
listviewtableviewdelegatemodel
3 Posts 2 Posters 1.2k Views 2 Watching
  • 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.
  • Q Offline
    Q Offline
    qwasder85
    wrote on 24 Aug 2015, 13:20 last edited by qwasder85
    #1

    I have a model that contains several QStandardItemModels. Now I want to create a view that displays a TableView for each of these QStandardItemModels.
    I had the idea to have a ListView that has a TableView as delegate, something like this:

    ListView {
        id: myListView
    
        anchors {
            fill: parent
            margins: 5
        }
    
        model: testModel
        delegate: CompareDelegate { }
    }
    

    And in CompareDelegate.qml:

    Item {
        id: base
    
        width: 500
        height: 300
    
        TableView {
            anchors.fill: parent
        }
    }
    

    How do I get the TableView inside the delegate to use the appropriate QStandardItemModel within the model of the ListView?
    I hope the question is somewhat clear.

    Thanks in advance.

    P 1 Reply Last reply 25 Aug 2015, 04:51
    0
    • Q qwasder85
      24 Aug 2015, 13:20

      I have a model that contains several QStandardItemModels. Now I want to create a view that displays a TableView for each of these QStandardItemModels.
      I had the idea to have a ListView that has a TableView as delegate, something like this:

      ListView {
          id: myListView
      
          anchors {
              fill: parent
              margins: 5
          }
      
          model: testModel
          delegate: CompareDelegate { }
      }
      

      And in CompareDelegate.qml:

      Item {
          id: base
      
          width: 500
          height: 300
      
          TableView {
              anchors.fill: parent
          }
      }
      

      How do I get the TableView inside the delegate to use the appropriate QStandardItemModel within the model of the ListView?
      I hope the question is somewhat clear.

      Thanks in advance.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 25 Aug 2015, 04:51 last edited by
      #2

      @qwasder85 A simple way would be to keep a Q_INVOKABLE function or a public slot in your model which will return these individual QStandardItemModels based on some property. Now since the TableView is inside the delegate assigned to ListView you can make use of index property and pass it to the function which will return the model. Something like

      Item {
          id: base
          ...
          TableView {
              anchors.fill: parent
              model: myListView.model.getModel(index) //or testModel.getModel(index)
          }
      }
      

      157

      Q 1 Reply Last reply 25 Aug 2015, 07:58
      0
      • P p3c0
        25 Aug 2015, 04:51

        @qwasder85 A simple way would be to keep a Q_INVOKABLE function or a public slot in your model which will return these individual QStandardItemModels based on some property. Now since the TableView is inside the delegate assigned to ListView you can make use of index property and pass it to the function which will return the model. Something like

        Item {
            id: base
            ...
            TableView {
                anchors.fill: parent
                model: myListView.model.getModel(index) //or testModel.getModel(index)
            }
        }
        
        Q Offline
        Q Offline
        qwasder85
        wrote on 25 Aug 2015, 07:58 last edited by
        #3

        @p3c0 This sounds like a very easy solution, I'll try it out. Thank you.

        1 Reply Last reply
        0

        1/3

        24 Aug 2015, 13:20

        • Login

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