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

TableView always reuses column 0 delegates and renders delegates partially if all columns are hidden

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.3
    • None
    • All

    Description

      On a TableView the ItemDelegate indicator rectangles will always be drawn, even if all columns width are set to 0 in the columnWidthProvider.

      On hiding the 0 column ItemDelegates will be pooled and immediately reused, even if the contentWidthProvider width is 0.

       

      Reproducer:

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      import Qt.labs.qmlmodels 1.0
      
      Window {
      	width: 640
      	height: 480
      	visible: true
      	
      	TableView {
      		id: tableView
      		
      		anchors.left: parent.left
      		anchors.right: parent.right
      		anchors.top: parent.top
      		anchors.bottom: button.top
      		
      		property var sizes: [100,100]
      		
      		columnWidthProvider: function( col ) {
      			return tableView.sizes[col];
      		}
      		
      		model: TableModel {
      			TableModelColumn { display: "name" }
      			
      			rows: [
      				{
      					"name": "cat",
      				},
      				{
      					"name": "dog",
      				},
      				{
      					"name": "bird",
      				}
      			]
      		}
      
      		delegate: ItemDelegate {
      			id: delegate
      		
      			text: model.column + " " + model.display
      			indicator: Rectangle {
      				width: 20
      				height: 20
      				color: "blue"
      			}
      			
      			onWidthChanged: {
      				console.debug("column:", model.column, "row:", model.row, "width", width)
      			}
      			TableView.onReused: {
      				console.debug( "REUSED", model.display )
      			}
      			TableView.onPooled: {
      				console.debug( "POOLED", model.display )
      			}
      		}
      	}
      	
      	Button {
      		id: button
      		
      		anchors.bottom: parent.bottom
      		
      		checkable: true
      		checked: false
      		text: button.checked ? "Column 0 Hidden" : "Column 0 Shown"
      		onCheckedChanged: {
      			if( button.checked ) {
      				tableView.sizes[0] = 0;
      			} else {
      				tableView.sizes[0] = 100;
      			}
      
      			Qt.callLater( tableView.forceLayout );
      		}
      	}
      }
      

      Attachments

        Issue Links

          Activity

            People

              richard Richard Moe Gustavsen
              tphaos Timo Phaosricharoen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: