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

Resizing TableView with columnWidthProvider corrupts contextX

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.14.0
    • Quick: Controls 2
    • None
    • All

    Description

      Resizing the width of a tableView with columnWidthProvider results in the contentX property having the wrong value. The following video demonstrate how the red rectangle, which has a fixed x of zero, jumps to the right as you resize the table view:

      https://youtu.be/dv_Y0XYaHT8

      import QtQuick 2.12
      import QtQml.Models 2.12
      import QtQuick.Layouts 1.12
      import QtQuick.Shapes 1.12
      import QtQuick.Controls 2.12
      import Qt.labs.qmlmodels 1.0
      
      
      Rectangle {
      
          id: root
          
          TableView {
              id: table
      
              anchors.fill: parent
      
              // This "overlay" element doesn't stay put.
              // https://doc.qt.io/qt-5/qml-qtquick-tableview.html#overlays-and-underlays
              Rectangle {
                  width: 20
                  height: table.contentHeight
                  color: 'red'
              }
      
              onWidthChanged: {
                  forceLayout() // columnWidthProvider calls are being triggered from this.
                  print('contentX', contentX) // shows that contextX does not match what is displayed.
              }
      
              // bug only occurs with column width provider
              columnWidthProvider: function(col) {
                  if(table.width > 150) {
                      return col % 2 == 0 ? 30 : 40
                  } else {
                      return col % 2 == 0 ? 0 : 40
                  }
              }
      
              delegate: Text {
                  text: 'here'
                  width: 50
              }
      
              model: TableModel {
                  TableModelColumn { display: 'buddy' }
                  TableModelColumn { display: 'date' }
                  TableModelColumn { display: 'dateTime' }
                  TableModelColumn { display: 'unsure' }
                  TableModelColumn { display: 'description' }
                  TableModelColumn { display: 'location' }
                  TableModelColumn { display: 'person' }
                  TableModelColumn { display: 'logged' }
                  TableModelColumn { display: 'color' }
                  TableModelColumn { display: 'nodal' }
                  rows: [
                      {
                          buddy: '',
                          date: (new Date),
                          dateTime: (new Date),
                          unsure: 'true',
                          description: 'Good times',
                          location: 'Anchorage',
                          person: 'Patrick',
                          logged: (new Date),
                          color: '#00000000',
                          nodal: 'false'
                      },
                      {
                          buddy: '',
                          date: (new Date),
                          dateTime: (new Date),
                          unsure: 'true',
                          description: 'Good times',
                          location: 'Anchorage',
                          person: 'Patrick',
                          logged: (new Date),
                          color: '#00000000',
                          nodal: 'false'
                      },
                      {
                          buddy: '',
                          date: (new Date),
                          dateTime: (new Date),
                          unsure: 'true',
                          description: 'Good times',
                          location: 'Anchorage',
                          person: 'Patrick',
                          logged: (new Date),
                          color: '#00000000',
                          nodal: 'false'
                      },
                      {
                          buddy: '',
                          date: (new Date),
                          dateTime: (new Date),
                          unsure: 'true',
                          description: 'Good times',
                          location: 'Anchorage',
                          person: 'Patrick',
                          logged: (new Date),
                          color: '#00000000',
                          nodal: 'false'
                      },
                      {
                          buddy: '',
                          date: (new Date),
                          dateTime: (new Date),
                          unsure: 'true',
                          description: 'Good times',
                          location: 'Anchorage',
                          person: 'Patrick',
                          logged: (new Date),
                          color: '#00000000',
                          nodal: 'false'
                      },
      
                  ]
              }
          }
      }
      

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              patrickkiddak Patrick Stinson
              Votes:
              3 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes