Results 1 to 3 of 3

Thread: QML QTableView dynamic row height

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows Android

    Default QML QTableView dynamic row height

    Hi.

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

    MsgWnd.png

    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:

    Qt Code:
    1. TableView {
    2. id: table_window
    3. model: messageModel
    4. anchors.fill: parent
    5.  
    6. headerVisible: false
    7.  
    8. TableViewColumn {
    9. role: "tbl_view_icon"
    10. width: 50
    11.  
    12. movable: false
    13. resizable: false
    14.  
    15. delegate: imageDelegate
    16. }
    17.  
    18.  
    19. TableViewColumn {
    20. role: "tbl_view_time"
    21. width: 70
    22.  
    23. movable: false
    24. resizable: false
    25.  
    26. delegate: textDelegate
    27. }
    28.  
    29. TableViewColumn {
    30. role: "tbl_view_msg"
    31. width: parent.width - 120
    32.  
    33. movable: false
    34. resizable: false
    35.  
    36. delegate: textDelegate
    37. }
    38.  
    39.  
    40. Component {
    41. id: textDelegate
    42. Item {
    43. id: f_item
    44. height: cell_txt.height
    45. Text {
    46. id: cell_txt
    47. width: parent.width
    48. anchors.margins: 4
    49. anchors.left: parent.left
    50. anchors.verticalCenter: parent.verticalCenter
    51. elide: styleData.elideMode
    52. text: styleData.value !== undefined ? styleData.value : ""
    53. color: styleData.textColor
    54. wrapMode: TextEdit.WordWrap
    55. }
    56. }
    57. }
    58.  
    59. Component {
    60. id: imageDelegate
    61. Item {
    62. Image {
    63. anchors.verticalCenter: parent.verticalCenter
    64. anchors.horizontalCenter: parent.horizontalCenter
    65. source: styleData.value !== undefined ? styleData.value : ""
    66. }
    67. }
    68. }
    69. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2016
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QML QTableView dynamic row height

    Have you solved this issue?

  3. #3
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QML QTableView dynamic row height

    You could try to set a row delegate like this:
    Qt Code:
    1. rowDelegate: Rectangle {
    2. anchors.left: parent.left
    3. anchors.right: parent.right
    4. color: styleData.selected ? "#448" : (styleData.alternate? "#ddd" : "#fff")
    5. height: 100
    6. }
    To copy to clipboard, switch view to plain text mode 
    and then try to make height adapting to whatever condition. Not sure if that's the way, but perhaps worth a try.

Similar Threads

  1. Replies: 1
    Last Post: 8th May 2013, 03:02
  2. how to set qtableview‘s row’height
    By calmspeaker in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2009, 06:50
  3. [solved]QListView dynamic item height
    By kernel_panic in forum Qt Programming
    Replies: 8
    Last Post: 17th March 2009, 14:05
  4. row height in QTreeView and QTableView
    By yuriry in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2008, 00:58
  5. QTextEdit - dynamic height
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 26th March 2007, 04:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.