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 seems to never update it's row count (updated)
QtWS25 Last Chance

ListView seems to never update it's row count (updated)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.1k 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.
  • E Offline
    E Offline
    Erlend E. Aasland
    wrote on last edited by Erlend E. Aasland
    #1

    I've got a ScrollView with a ListView embedded. I've got a delegate which prepares a custom QML widget, works like a charm. And I update the ListModel using .append(), which also works very well. However, when stuff get added to the ListModel, it's just added on the same line (the first line) of the ListView. I've tried setting spacing: 1 and keyNavigationEnabled: true, but there is still only one line. What am I doing wrong?

    ApplicationWindow {
    property ListModel offset_model: ListModel { id: model }
    
    function on_new_offset(tag, name, value) { 
           offset_model.append( {"tag": tag, "name": name, "value": value }) 
    }
    
    ScrollView {
      anchors.fill: parent
      clip: true
    
      Component {
        id: item_delegate
        Row {
          ConfigLine { /* custom widget */
            config_idx: index + 1
            config_name: name
            config_tag: tag
            config_value: value
          }
        }
    
      ListView {
        id: config_list
        anchors.fill: parent
        delegate: item_delegate
        model: model
        spacing: 1
        keyNavigationEnabled: true
      }
    }
    }
    
    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Erlend-E-Aasland Try providing width and height to ConfigLine.

      157

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Erlend E. Aasland
        wrote on last edited by Erlend E. Aasland
        #3

        @p3c0 Thanks, but didn't help.

        However, dropping ListView and using Column { Repeater { } } seems to work. Also I have to drop my custom widget, and re-create it inside the delegate. Now the code looks like this, and it works. But, it's extremely irritating having to create the Row { } inline, instead of just importing a custom object.

        ScrollView {
        	anchors.fill: parent
        	clip: true
        
        /* the delegate that will load the new component into the list model */
        	Component {
        		id: item_delegate
        		Row {
        			spacing: 5
        			Text {
        				text: name + ":"
        				MouseArea {
        					id: mouse_area
        					anchors.fill: parent
        				}
        				ToolTip {
        					text: tag
        					visible: mouse_area.pressed
        				}
        			}
        			TextEdit {
        				text: value
        			}
        		}
        	}
        
        	Column {
        		anchors.fill: parent
        		spacing: 5
        
        		Repeater {
        			anchors.fill: parent
        			delegate: item_delegate
        			model: model
        		}
        	}
        }
        
        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