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. Qt 6.5: QML TableView lose resizing ability when using columnWidthProvider
Forum Updated to NodeBB v4.3 + New Features

Qt 6.5: QML TableView lose resizing ability when using columnWidthProvider

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 726 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.
  • R Offline
    R Offline
    romain.donze
    wrote on last edited by
    #1

    In Qt 6.5 TableView, the ability to resize rows is very welcome as it was something that was available in the old QtQuick.Controls 1. But I have noticed that when using columnWidthProvider

    columnWidthProvider: function(column) {
        if(columnsModel.at(column).visible)
            return table.view.columnWidth(column)
        return 0
    }
    

    Make it that the rows are not resizable anymore because columnWidthProvider is invoke every time I drag the cell to resize it, so the size is always reseted to the value returned by columnWidthProvider.

    Am I doing something wrong or is there a way to overcome this issue?

    1 Reply Last reply
    3
    • S Offline
      S Offline
      Sakthiuma
      wrote on last edited by Sakthiuma
      #2

      I know it's an old post but if anyone is looking for the solution. I faced the same problem. column width provider enforces the width and blocks the resize option. The workaround for this is to create a function for columnwidthprovider and set the width of the delegates directly using the function

      1 Reply Last reply
      1
      • Z Offline
        Z Offline
        zachary
        wrote last edited by zachary
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zachary
          wrote last edited by zachary
          #4

          some tips for this.

          ApplicationWindow {
              visible: true
              width: 640
              height: 480
              title: qsTr("HeaderView")
              TableModel {
                  id: qmlTabModel
                  TableModelColumn { display: "name" }
                  TableModelColumn { display: "color" }
                  TableModelColumn { display: "age" }
                  rows: [
                      {
                          "name": "cat",
                          "color": "black",
                          "age": "1.1"
                      },
                      {
                          "name": "dog",
                          "color": "brown",
                          "age": "1.2"
                      },
                      {
                          "name": "bird",
                          "color": "white",
                          "age": "1.3"
                      }
                  ]
              }
          
              Rectangle {
                  id: bgtab
                  anchors.fill: parent
                  color: Qt.styleHints.appearance === Qt.Light ? palette.mid : palette.midlight
                          onWidthChanged: {
                              tableView.forceLayout()
                          }
                  
                        HorizontalHeaderView {
                      id: horizontalHeader
                      anchors.left: tableView.left
                      anchors.right: parent.right;
                      anchors.top: parent.top
                      syncView: tableView
                      clip: true
                      model: qmlTabModel
                      delegate: Label {
                          text: qmlTabModel.columns[column].display
                      }
                  }
                  VerticalHeaderView {
                      id: verticalHeader
                      anchors.top: tableView.top
                      anchors.left: parent.left
                      syncView: tableView
                      clip: true
                  }
          
                  TableView {
                      id: tableView
                      anchors.left: verticalHeader.right
                      anchors.top: horizontalHeader.bottom
                      anchors.bottom: parent.bottom
                      contentWidth: parent.width;
                      columnSpacing: 1
                      rowSpacing: 1
                      boundsBehavior: Flickable.StopAtBounds
                      property var columnWidths: [100, 50, bgtab.width]
                      columnWidthProvider: function(column) {
                          let w = explicitColumnWidth(column) 
                          if (w >= 0 && column !== (columns - 1)) {
                              columnWidths[column] = w;
                              return w;
                          }
                          if (column === (columns - 1)) {
                              w =  columnWidths[column];
                              let i = columns - 1;
                              while(--i !== -1) w -= columnWidths[i];
                                  return w;
                          }
                          return columnWidths[column];
                      }
          
          
                      model: qmlTabModel
          
                      delegate: Rectangle {
                          implicitHeight: 20
                          color: palette.base
                          Label {
                              text: display
                          }
                      }
                  }
              }
          }
          
          
          1 Reply Last reply
          0

          • Login

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