Results 1 to 6 of 6

Thread: listview height

  1. #1
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default listview height

    Hello Qt Masters,

    I wanted to set a dynamic Listview height which will depends on the height of the delegate items. Because I included the listview into a ColumnLayout, and it needs to have a height so that the next element won't overlapped. I've tried listview's contentHeight and implicitHeight properties but it isn't working. Btw, the delegate item has no specific height set also.

    Any idea on how to implement it? Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: listview height

    I think you'll need to describe your goal in more detail.

    Do delegates for difference indexes have uniform or different height?
    Do you want a certain number of delegates visible, or all, or a minimum or a maximum?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: listview height

    Quote Originally Posted by anda_skoa View Post
    I think you'll need to describe your goal in more detail.

    Do delegates for difference indexes have uniform or different height?
    Do you want a certain number of delegates visible, or all, or a minimum or a maximum?

    Cheers,
    _
    Thank you for your response anda_skoa

    Yes, delegates have uniform heights and all items should be visible.
    The buttons overlaps in listview item because no height being set on it, which I don't want to hard code the height.

    Here's my code:

    Qt Code:
    1. Item {
    2. ColumnLayout
    3. {
    4. id: body
    5. anchors.fill: parent
    6.  
    7. ListView
    8. {
    9. id: connDetails
    10. anchors.fill: parent
    11. interactive: false
    12. model: connModel
    13. delegate: connDelegate
    14. }
    15. Button {
    16. text: "Ok"
    17. }
    18. Button {
    19. text: "View"
    20. }
    21. Button {
    22. text: "Cancel"
    23. }
    24. }
    25.  
    26. ListModel
    27. {
    28. id: connModel
    29. ListElement
    30. {
    31. serverName: "connection1"
    32. serverIp: "192.168.1.8"
    33. }
    34. ListElement
    35. {
    36. serverName: "connection2"
    37. serverIp: "192.168.1.7"
    38. }
    39. }
    40.  
    41. Component
    42. {
    43. id: connDelegate
    44.  
    45. GridLayout
    46. {
    47. columns: 2
    48. rows: 2
    49. columnSpacing: 20
    50.  
    51. Text
    52. {
    53. text: qsTr("Server name:")
    54. color: "white"
    55. }
    56.  
    57. Text
    58. {
    59. text: qsTr(serverName)
    60. color: "white"
    61. }
    62.  
    63. Text
    64. {
    65. text: qsTr("Server IP:")
    66. color: "white"
    67. }
    68.  
    69. Text
    70. {
    71. text: qsTr(serverIp)
    72. color: "white"
    73. }
    74. }
    75.  
    76. }
    77. }
    To copy to clipboard, switch view to plain text mode 

    Cheers!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: listview height

    If all items should be visible, i.e. does that mean you are not needing the list view's scrolling capability?
    Which of the list view capabilities do you need?

    I.e. why use a list view and not simply a Repeater?

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    joko (2nd January 2015)

  6. #5
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: listview height

    Quote Originally Posted by anda_skoa View Post
    If all items should be visible, i.e. does that mean you are not needing the list view's scrolling capability?
    Which of the list view capabilities do you need?

    I.e. why use a list view and not simply a Repeater?

    Cheers,
    _
    Wow! Using Repeater is the best option!

    Thanks!

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: listview height

    Quote Originally Posted by joko View Post
    Wow! Using Repeater is the best option!


    Just a couple of tips:

    1) when referencing model data in a delegate it is usually helpful for later readability to make that referencing more explicit.
    E.g.. instead of using just "serverName" write "model.serverName"

    This makes it more obvious which data is local to the delegate and which data is from the model

    2) this is probably just because this is more an example code to demonstrate the problem, but qsTr(serverName) does not make any sense. "serverName" is a property from the model. if is contains translatable text it has had to be translated at its source already.

    Cheers,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    joko (5th January 2015)

Similar Threads

  1. listview
    By ganeshgladish in forum Newbie
    Replies: 1
    Last Post: 23rd June 2013, 11:51
  2. Qml Listview
    By ganeshgladish in forum Newbie
    Replies: 1
    Last Post: 19th June 2013, 09:41
  3. How to set custom height for ListView & ComboBox items
    By rawfool in forum Qt Programming
    Replies: 1
    Last Post: 30th September 2011, 11:39
  4. qml listview
    By Le_B in forum Qt Quick
    Replies: 1
    Last Post: 25th May 2011, 14:01
  5. Qt listView total height
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2008, 19:16

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.