Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-31028

TableView doesn't update correctly if columns change.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.1.0 RC1
    • 5.1.0
    • Quick: Controls 1
    • None
    • Mac OS 10.8
    • c47c502e794f7ae37c516a1db123139d9dc1270d

    Description

      I have a TableView that allows the number columns and roles to change dynamically. When I update the columns, the TableView's column headers update correctly, but the cells in the table are empty. They should be filled with data from the model instead of being empty.

      A workaround to this bug is to set the TableView's model to null, and then set the model back to it's original value. Then the model's data shows up in the table view.

             Item {
                  TableView {
                      id: tableView
                      anchors.fill: parent
      
      
      //                model: csvPreviewModelId
      
                      /**
                        This populates the table columns with data dynamically
                        */
                      function updateColumns() {
                          tableView.model = null //WORKAROUND
                          var columns = csvPreviewModelId.columnNames;
                          var columnObjects = [];
                          for(var i in columns) {
                              var columnName = columns[i]
                              var newColumn = tableViewColumnComponent.createObject(tableView,
                                                                                    {role: columnName, title: columnName})
                              columnObjects.push(newColumn)
                          }
      
                          tableView.columns = columnObjects
                          tableView.model = csvPreviewModelId //WORKAROUND
                      }
      
                      Component.onCompleted: {
                          tableView.updateColumns()
                      }
                  }
      
                  Connections {
                      target: csvPreviewModelId
                      onColumnNamesChanged: tableView.updateColumns()
                  }
      
                  Component {
                      id: tableViewColumnComponent
                      TableViewColumn { }
                  }
              }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            vpicaver Philip Schuchardt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes