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. ListView: using external model?
Forum Updated to NodeBB v4.3 + New Features

ListView: using external model?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 485 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I've created a component (most stuff deleted):

    Rectangle {
        ListModel {
            id: activityModel
            ListElement { parameter: "Capacity" }
            ListElement { parameter: "Speed" }
            ListElement { parameter: "Speed limits" }
        }
    
        Component {
            id: activityDelegate
            Text {
                id: paramName
                text: model.parameter
            }
        }
    
        ListView {
            id: activityView
            model: activityModel
            delegate: activityDelegate
        }
    }
    

    I'd like to remove the model from this component, and furnish from the instantiator. I assume this is possible; how best to go about it?

    Thanks...

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2
      Rectangle {
          property alias model: activityView.model
      
          Component {
              id: activityDelegate
              Text {
                  id: paramName
                  text: model.parameter
              }
          }
      
          ListView {
              id: activityView
              delegate: activityDelegate
          }
      }
      

      C++ is a perfectly valid school of magic.

      mzimmersM 1 Reply Last reply
      2
      • fcarneyF fcarney
        Rectangle {
            property alias model: activityView.model
        
            Component {
                id: activityDelegate
                Text {
                    id: paramName
                    text: model.parameter
                }
            }
        
            ListView {
                id: activityView
                delegate: activityDelegate
            }
        }
        
        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @fcarney that's pretty slick. Alias properties are fairly powerful, aren't they?

        Thanks for the help...

        fcarneyF 1 Reply Last reply
        1
        • mzimmersM mzimmers

          @fcarney that's pretty slick. Alias properties are fairly powerful, aren't they?

          Thanks for the help...

          fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          @mzimmers Happy New Year!

          C++ is a perfectly valid school of magic.

          mzimmersM 1 Reply Last reply
          0
          • fcarneyF fcarney

            @mzimmers Happy New Year!

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @fcarney back at ya...hope this year works well for you.

            mzimmersM 1 Reply Last reply
            1
            • mzimmersM mzimmers

              @fcarney back at ya...hope this year works well for you.

              mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #6

              OK, I feel really silly asking this, because I'm the one who introduced it into this topic, but...where can I find documentation on what this line does:

              text: model.parameter
              

              Thanks...

              GrecKoG 1 Reply Last reply
              0
              • mzimmersM mzimmers

                OK, I feel really silly asking this, because I'm the one who introduced it into this topic, but...where can I find documentation on what this line does:

                text: model.parameter
                

                Thanks...

                GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #7

                @mzimmers here : https://doc.qt.io/qt-6/qtquick-modelviewsdata-modelview.html#models

                Note that you can now use required properties instead. Be careful that having a delegate with any required property will prevent you from using implicit context properties (like the model.parameter here) like before, you can't mix and match.

                1 Reply Last reply
                1
                • mzimmersM mzimmers has marked this topic as unsolved on
                • mzimmersM mzimmers has marked this topic as solved on

                • Login

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