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 - how to add new item
Forum Updated to NodeBB v4.3 + New Features

ListView - how to add new item

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 248 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.
  • P Offline
    P Offline
    PawlosCK
    wrote on last edited by
    #1

    I have simple listview. I am trying to use "append" to add new item, but item is added at index 0. How to add new item in next line?

    
    Window
    {
        id: alarmListWindow
    
        width: 400
        height: 400
    
        ListModel
        {
            id: modelID
    
    //        ListElement
    //        {
    //            idAlarm: ""
    //            typeAlarm: ""
    //            messageAlarm: ""
    //        }
        }
        Component
        {
            id: delegatID
            Rectangle
            {
                id: alarmItemDelegate
                x: 0
                y: 0
                Text
                {
                    id: idAl
                    y: parent.y
                    text: "ID: " + model.idAlarm
                }
                Text
                {
                    id: messAl
                    y: idAl.height
                    text: "message: " + model.messageAlarm
                }
            }
        }
        ListView
        {
            id: listviewID
            anchors.fill: parent
            width: 180; height: 200
            model: modelID
            delegate: delegatID
        }
        Component.onCompleted:
        {
    //        modelID.append( { "idAlarm": "12345678", "typeAlarm": "TV", "messageAlarm": "Jakas wiadomosc" } )
        }
        Timer
        {
            id: timerUpdateListView
            interval: 1000; running: true; repeat: true; triggeredOnStart: true
            onTriggered: updateListView()
        }
        function updateListView()
        {
            modelID.append( { "idAlarm": "alarm.timer_remaining", "typeAlarm": "TT", "messageAlarm": "Jakas wiadomosc" } )
        }
    }
    
    
    B 1 Reply Last reply
    0
    • P PawlosCK

      I have simple listview. I am trying to use "append" to add new item, but item is added at index 0. How to add new item in next line?

      
      Window
      {
          id: alarmListWindow
      
          width: 400
          height: 400
      
          ListModel
          {
              id: modelID
      
      //        ListElement
      //        {
      //            idAlarm: ""
      //            typeAlarm: ""
      //            messageAlarm: ""
      //        }
          }
          Component
          {
              id: delegatID
              Rectangle
              {
                  id: alarmItemDelegate
                  x: 0
                  y: 0
                  Text
                  {
                      id: idAl
                      y: parent.y
                      text: "ID: " + model.idAlarm
                  }
                  Text
                  {
                      id: messAl
                      y: idAl.height
                      text: "message: " + model.messageAlarm
                  }
              }
          }
          ListView
          {
              id: listviewID
              anchors.fill: parent
              width: 180; height: 200
              model: modelID
              delegate: delegatID
          }
          Component.onCompleted:
          {
      //        modelID.append( { "idAlarm": "12345678", "typeAlarm": "TV", "messageAlarm": "Jakas wiadomosc" } )
          }
          Timer
          {
              id: timerUpdateListView
              interval: 1000; running: true; repeat: true; triggeredOnStart: true
              onTriggered: updateListView()
          }
          function updateListView()
          {
              modelID.append( { "idAlarm": "alarm.timer_remaining", "typeAlarm": "TT", "messageAlarm": "Jakas wiadomosc" } )
          }
      }
      
      
      B Offline
      B Offline
      Bob64
      wrote on last edited by
      #2

      @PawlosCK Hi - your list is being appended to. The problem is in its display in the ListView. You need to size your item delegate.

      For example if you add

             Rectangle
              {
                  id: alarmItemDelegate
                  //x: 0 NOT NEEDED??
                  //y: 0
                  height: 40               \\ <<<<
                  width: listviewID.width  \\ <<<<
                  Text
                  {
                      id: idAl
                      y: parent.y
                      text: "ID: " + model.idAlarm
                  }
                  ... 
      
      1 Reply Last reply
      1

      • Login

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