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. Changing TableView columnWidthProvider from 0 (hidden) to non-zero
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 1 Posters 1.1k Views
  • 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
    Puya
    wrote on last edited by
    #1

    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. Is this a bug in TableView? If not how can I circumvent this issue? I think if not a bug, this would be incompatible with design of other QtQuick components such as for example the Window that has the TreeView inside, since it first creates its contentItem at size 0x0 and then resizes it to the final Window size. Therefore the TableView would only behave properly if I set a fake initial size for it if used inside a Window (which I prefer not to do).

    Example code:

    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
    
    		/* does not 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
                }
            }
        }
    }
    
    1 Reply Last reply
    0
    • P Offline
      P Offline
      Puya
      wrote on last edited by
      #3

      Turns out it was a bug:
      https://bugreports.qt.io/browse/QTBUG-92076

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Puya
        wrote on last edited by
        #2
        This post is deleted!
        1 Reply Last reply
        0
        • P Offline
          P Offline
          Puya
          wrote on last edited by
          #3

          Turns out it was a bug:
          https://bugreports.qt.io/browse/QTBUG-92076

          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