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

Changing TableView columnWidthProvider from 0 (hidden) to non-zero not effective

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 5.15.1
    • None
    • All

    Description

      I have a TableView inside my Window. I am using columnWidthProvider to provide the column width to be a specific size, and I am calling onWidthChanged: forceLayout() to force updates after width changes. However if the initial value returned by columnWidthProvider is zero (meaning telling TableView to hide that column) then the update does not have any effect.

      I think if not a bug, this would be incompatible with design of other QtQuick components such as Window that has the TreeView inside, since Window first creates its contentItem at 0x0 and then resizes it to the final Window size. Therefore TableView cannot be used inside a Window unless I set a dummy initial size for the column. A sample code would be like this:

      {{}}

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import Qt.labs.qmlmodels 1.0
      
      Window {
          width: 400
          height: 400
          visible: true
      
          TableView {
              anchors.fill: parent
              columnSpacing: 1
              rowSpacing: 1
              boundsBehavior: Flickable.StopAtBounds
      
      		/* cannot resize and have the column appear */
      		columnWidthProvider: function (column) { return column === 0 ? width : 0 }
      		onWidthChanged: forceLayout()
      		/**********************************************/
      
              model: TableModel {
                  TableModelColumn { display: "checked" }
                  TableModelColumn { display: "amount" }
                  TableModelColumn { display: "fruitType" }
                  TableModelColumn { display: "fruitName" }
                  TableModelColumn { display: "fruitPrice" }
      
                  // Each row is one type of fruit that can be ordered
                  rows: [
                      {
                          // Each property is one cell/column.
                          checked: false,
                          amount: 1,
                          fruitType: "Apple",
                          fruitName: "Granny Smith",
                          fruitPrice: 1.50
                      },
                      {
                          checked: true,
                          amount: 4,
                          fruitType: "Orange",
                          fruitName: "Navel",
                          fruitPrice: 2.50
                      },
                      {
                          checked: false,
                          amount: 1,
                          fruitType: "Banana",
                          fruitName: "Cavendish",
                          fruitPrice: 3.50
                      }
                  ]
              }
              delegate:  TextInput {
                  text: model.display
                  padding: 12
                  selectByMouse: true
      
                  onAccepted: model.display = text
      
                  Rectangle {
                      anchors.fill: parent
                      color: "#efefef"
                      z: -1
                  }
              }
          }
      }

      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
              mmi_puya Puya Daravi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes