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

delegate a ListView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 646 Views 1 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.
  • C Offline
    C Offline
    cosmoff
    wrote on last edited by
    #1

    Hello,

    I have in my main.qml :

    Classification{
    classifObject: classifModel ? classifModel.technologyClassificationModelList : null
    height: 300
    width: parent.width

    anchors { left: parent.left ;}
    

    }

    and in my Classification.qml I have :

    ListView{
    id: idClassifModel

    property var classifObject
    
    width: parent.width
    height: parent.height
    model: classifObject
    clip: true
    orientation: ListView.Vertical
    verticalLayoutDirection: ListView.TopToBottom
    
    delegate: ListView {
        width: parent.width
        height: 50
        model: classifObject.classifPrimaireList
    
    
        delegate: Rectangle{
    
            height: 50
            width: 150
    
            Text {
                text: name
                font.pixelSize: 25
                font.bold: true
                color: graphicIdentity.raspberry
                anchors.centerIn: parent
            }
        }
    
    }
    

    but text: name does not work. Do you have an idea ?

    thank you for your help

    KroMignonK 1 Reply Last reply
    0
    • C cosmoff

      Hello,

      I have in my main.qml :

      Classification{
      classifObject: classifModel ? classifModel.technologyClassificationModelList : null
      height: 300
      width: parent.width

      anchors { left: parent.left ;}
      

      }

      and in my Classification.qml I have :

      ListView{
      id: idClassifModel

      property var classifObject
      
      width: parent.width
      height: parent.height
      model: classifObject
      clip: true
      orientation: ListView.Vertical
      verticalLayoutDirection: ListView.TopToBottom
      
      delegate: ListView {
          width: parent.width
          height: 50
          model: classifObject.classifPrimaireList
      
      
          delegate: Rectangle{
      
              height: 50
              width: 150
      
              Text {
                  text: name
                  font.pixelSize: 25
                  font.bold: true
                  color: graphicIdentity.raspberry
                  anchors.centerIn: parent
              }
          }
      
      }
      

      but text: name does not work. Do you have an idea ?

      thank you for your help

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #2

      @cosmoff Have you tried to use model.<property_name> to avoid clashing between delegate properties and data model?
      Like this:

          delegate: Rectangle{
      
              height: 50
              width: 150
      
              Text {
                  text: model.name
                  font.pixelSize: 25
                  font.bold: true
                  color: graphicIdentity.raspberry
                  anchors.centerIn: parent
              }
          }
      
      

      See http://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html#models for more details;

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      C 1 Reply Last reply
      0
      • KroMignonK KroMignon

        @cosmoff Have you tried to use model.<property_name> to avoid clashing between delegate properties and data model?
        Like this:

            delegate: Rectangle{
        
                height: 50
                width: 150
        
                Text {
                    text: model.name
                    font.pixelSize: 25
                    font.bold: true
                    color: graphicIdentity.raspberry
                    anchors.centerIn: parent
                }
            }
        
        

        See http://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html#models for more details;

        C Offline
        C Offline
        cosmoff
        wrote on last edited by
        #3

        @KroMignon
        I tryed but it does not work :( Is it possible to do a delegate of a ListView like I do?

        KroMignonK 1 Reply Last reply
        0
        • C cosmoff

          @KroMignon
          I tryed but it does not work :( Is it possible to do a delegate of a ListView like I do?

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @cosmoff I think I have read too quickly your QML... Sorry.

          I dont understand your QML code in Classification.
          Is the model for the inner ListView a propertie from items in main model?
          If yes, i would write it like this:

          ListView{
              id: idClassifModel
              width: parent.width
              height: parent.height
              clip: true
              orientation: ListView.Vertical
              verticalLayoutDirection: ListView.TopToBottom
          
              delegate: ListView {
                  width: parent.width
                  height: 50
                  model: classifPrimaireList
                  delegate: Rectangle{
                      height: 50
                      width: 150
          
                      Text {
                          text: name
                          font.pixelSize: 25
                          font.bold: true
                          color: graphicIdentity.raspberry
                          anchors.centerIn: parent
                      }
                  }
              }
          }
          

          And for main.qml

          Classification{
              model: !!classifModel ? classifModel.technologyClassificationModelList : 0
              height: 300
              width: parent.width
          
              anchors { left: parent.left ;}
          
          }
          

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0
          • Shrinidhi UpadhyayaS Offline
            Shrinidhi UpadhyayaS Offline
            Shrinidhi Upadhyaya
            wrote on last edited by
            #5

            Hi @cosmoff , i did not understand your model assignment,from what i understood i have modified a bit of your code please have look into it:-

            Classification.qml

            ListView{
            id: idClassifModel
            
            property var classifObject
            
            width: parent.width
            height: parent.height
            model: classifObject
            clip: true
            orientation: ListView.Vertical
            verticalLayoutDirection: ListView.TopToBottom
            interactive: false
            spacing: 100
            
            delegate:
            
                ListView {
                width: parent.width
                height: 50
                model: classifObject
                interactive: true
            
                delegate: Rectangle{
            
                    height: 25
                    width: parent.width
                    z:1
                    color: "yellow"
                    border.color: "blue"
            
                    Text {
                        text: name
                        font.pixelSize: 25
                        font.bold: true
                        color: "pink"
                        anchors.centerIn: parent
                    }
                }
            }}
            

            main.qml

            ListModel {
                    id: dummyModel
            
                    ListElement {
                        name: "0"
                    }
            
                    ListElement {
                        name: "1"
                    }
                }
            
            
                Classification{
                    anchors.fill: parent
                    classifObject: dummyModel
                    anchors { left: parent.left ;}
                }
            

            Shrinidhi Upadhyaya.
            Upvote the answer(s) that helped you to solve the issue.

            1 Reply Last reply
            1
            • C Offline
              C Offline
              cosmoff
              wrote on last edited by
              #6

              I just put :
              delegate: ListView {
              width: parent.width
              height: 50
              model: classifPrimaireList
              delegate: Rectangle{
              height: 50
              width: 150

                      Text {
                          text: name
                          font.pixelSize: 25
                          font.bold: true
                          color: graphicIdentity.raspberry
                          anchors.centerIn: parent
                      }
                  }
              }
              

              }

              and it works !
              thank a lot !

              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