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. TableView QtQuick 2.12 did not fill Layout (dont fill anything at all)
Forum Updated to NodeBB v4.3 + New Features

TableView QtQuick 2.12 did not fill Layout (dont fill anything at all)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 1.4k Views 1 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.
  • S Offline
    S Offline
    SergeyK12
    wrote on last edited by SergeyK12
    #1

    Hi, i'm starting to investigate qml and get the following problem.
    When i'm trying to use TableView from quick 2
    it didnt fill window! Filling perfectly work on buttons and other object in examples, but not table!
    What i doing wrong?
    Here is qml example with my own model

    import QtQuick 2.12
    import MyModule 1.0
    import QtQuick.Window 2.12
    import QtQuick.Layouts 1.12
    import QtQuick.Controls 2.5
    
    ApplicationWindow {	
        visible: true
        width: 1000
        height: 250
    	
        ColumnLayout {
    	id:mainLayout
            anchors.fill: parent
    
    	TableView {	
    		anchors.fill: parent
    		Layout.fillWidth: true
    		Layout.fillWidth: true
    		columnSpacing: 0
    		rowSpacing: 0
    		clip: true
    		model: StandardModel {}
    		
    		delegate: Rectangle {
    			implicitWidth: parent.width/4;
    			implicitHeight: 50
    			border.color: "blue"
    			border.width: 1
    			color: (heading==true) ? "red" : "green"
    			Text {
    				text: tabledata
    				font.pointSize: 12
    				anchors.centerIn: parent
    			}
    		}
    	}
    }
    

    Here is what i'm talking about. When i change window table didnt changed
    0_1557091107582_qml_error.JPG

    raven-worxR 1 Reply Last reply
    0
    • S SergeyK12

      Hi, i'm starting to investigate qml and get the following problem.
      When i'm trying to use TableView from quick 2
      it didnt fill window! Filling perfectly work on buttons and other object in examples, but not table!
      What i doing wrong?
      Here is qml example with my own model

      import QtQuick 2.12
      import MyModule 1.0
      import QtQuick.Window 2.12
      import QtQuick.Layouts 1.12
      import QtQuick.Controls 2.5
      
      ApplicationWindow {	
          visible: true
          width: 1000
          height: 250
      	
          ColumnLayout {
      	id:mainLayout
              anchors.fill: parent
      
      	TableView {	
      		anchors.fill: parent
      		Layout.fillWidth: true
      		Layout.fillWidth: true
      		columnSpacing: 0
      		rowSpacing: 0
      		clip: true
      		model: StandardModel {}
      		
      		delegate: Rectangle {
      			implicitWidth: parent.width/4;
      			implicitHeight: 50
      			border.color: "blue"
      			border.width: 1
      			color: (heading==true) ? "red" : "green"
      			Text {
      				text: tabledata
      				font.pointSize: 12
      				anchors.centerIn: parent
      			}
      		}
      	}
      }
      

      Here is what i'm talking about. When i change window table didnt changed
      0_1557091107582_qml_error.JPG

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @SergeyK12
      https://doc-snapshots.qt.io/qt5-5.12/qml-qtquick-tableview.html#columnWidthProvider-prop

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SergeyK12
        wrote on last edited by SergeyK12
        #3

        Thanks for your response.
        I almost try it and it isnt worked

        TableView {	
            anchors.fill: parent
            Layout.fillWidth: true
            columnWidthProvider: function (column) { return mainLayout.width/4 }
            rowHeightProvider  : function (row) { return mainLayout.height/3 }
        

        Yep, its calc width in the beggining of the programm, but when i changed size of mainwindow nothing changed!
        Its not connected with mainLayout.width value (but it is changed)

        And thats happend if i chnge main window size faster (width and height of table cells are different)
        0_1557093522629_qml_error.JPG

        raven-worxR 1 Reply Last reply
        0
        • S SergeyK12

          Thanks for your response.
          I almost try it and it isnt worked

          TableView {	
              anchors.fill: parent
              Layout.fillWidth: true
              columnWidthProvider: function (column) { return mainLayout.width/4 }
              rowHeightProvider  : function (row) { return mainLayout.height/3 }
          

          Yep, its calc width in the beggining of the programm, but when i changed size of mainwindow nothing changed!
          Its not connected with mainLayout.width value (but it is changed)

          And thats happend if i chnge main window size faster (width and height of table cells are different)
          0_1557093522629_qml_error.JPG

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @SergeyK12
          its all in the docs:
          https://doc-snapshots.qt.io/qt5-5.12/qml-qtquick-tableview.html#row-heights-and-column-widths

          If you change the values that a rowHeightProvider or a columnWidthProvider return for rows and columns inside the viewport, you must call forceLayout. This informs TableView that it needs to use the provider functions again to recalculate and update the layout.

          so whenever your width/height changes call forceLayout()

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          4
          • S Offline
            S Offline
            SergeyK12
            wrote on last edited by
            #5

            Thanks! Its worked!

            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