Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qml TableView dynamic row height
Forum Updated to NodeBB v4.3 + New Features

Qml TableView dynamic row height

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 3.9k 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.
  • K Offline
    K Offline
    Khachatur
    wrote on last edited by
    #1

    Hi.

    In my Android application I have a message window which is qml tableview:

    !https://www.dropbox.com/s/8fz0iwg8rg9uic3/MsgWnd.png?dl=0()!

    The problem is that if the length of the text is longer than width of cell, the text is wrapped, but the height of row is not increased. You could see it in the last row of attached picture.

    Here is the code of table view:
    @
    TableView {
    id: table_window
    model: messageModel
    anchors.fill: parent

        headerVisible: false
    
        TableViewColumn {
            role: "tbl_view_icon"
            width: 50
    
            movable: false
            resizable: false
    
            delegate: imageDelegate
        }
    
    
        TableViewColumn {
            role: "tbl_view_time"
            width: 70
    
            movable: false
            resizable: false
    
            delegate: textDelegate
        }
    
        TableViewColumn {
            role: "tbl_view_msg"
            width: parent.width - 120
    
            movable: false
            resizable: false
    
            delegate: textDelegate
        }
    
    
        Component {
            id: textDelegate
            Item {
                id: f_item
                height: cell_txt.height
                Text {
                    id: cell_txt
                    width: parent.width
                    anchors.margins: 4
                    anchors.left: parent.left
                    anchors.verticalCenter: parent.verticalCenter
                    elide: styleData.elideMode
                    text: styleData.value !== undefined  ? styleData.value : ""
                    color: styleData.textColor
                    wrapMode: TextEdit.WordWrap
                }
            }
        }
    
        Component {
            id: imageDelegate
            Item {
                Image {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.horizontalCenter: parent.horizontalCenter
                    source: styleData.value !== undefined  ? styleData.value : ""
                }
            }
        }
    }
    

    @

    How to make the row height fit its content? Please, help.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Khachatur
      wrote on last edited by
      #2

      Hi, SGaist!

      Thank you for your replaying.

      Yes, I have tried not to set resizable to false, but it doesn't work. Because resizable property it is for columns width, but not height.

      Also, I have tried to use rowDelegate like this:

      @
      rowDelegate: Rectangle {
      height: 50

          color: styleData.selected ? "#448" : (styleData.alternate? "#eee" : "#fff")
      

      }
      @

      But I don't want to hard code or calculate each row height by myself, I want TableView to calculate its row height.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Can you share a minimal complete example that reproduce the behavior ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Khachatur
          wrote on last edited by
          #4

          Hi, SGaist.

          Yes, I can. Here is the simple project: https://www.dropbox.com/s/vitelj126rak9vt/TableView-sample.zip?dl=0

          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