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. How to make qml TableView row height dynamically adapt to content

How to make qml TableView row height dynamically adapt to content

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.2k 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.
  • Mad KimM Offline
    Mad KimM Offline
    Mad Kim
    wrote on last edited by
    #1

    The problem is the following:

    If the length of the text is longer than the width of the cell, the text is wrapped, but the height of the row is not increased. which displays the rest of the text chopped. My question is:
    How to make qml TableView row height dynamically adapt to the content (for each cell depending on the size of its contained text)?

    The QML part:

    Window {
    id: window
    visible: true
    width: 440
    height: 400
    title: qsTr("Table test")
    
    ListModel {
        id: stringsModel
    
        ListElement {
            ID: 0
            String: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam'
        }
        ListElement {
            ID: 1
            String: 'This is a test string'
        }ListElement {
            ID: 1
            String: 'This is another test string'
        }
    }
    
    TableView {
        anchors.fill: parent
        frameVisible: false
        model: stringsModel
    
        TableViewColumn { role: "ID"; title: "ID"; width: window.width / 2 }
        TableViewColumn { role: "String"; title: "String"; width: window.width / 2; delegate: stringDelegate;}
    
        Component {
            id: stringDelegate
            Item {
                id: stringItem
                Text {
                    id: stringTxt
                    width: parent.width
                    text: styleData.value
                    wrapMode: TextEdit.WordWrap
                }
            }
        }
    }
    

    Thanks.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      rowDelegate is the answer. You need to change the rowDelegate to change the height of default TableView.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      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