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



  • 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
      }
    }
    }
    

  • Moderators

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



  • @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
    		}
    	}
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.