Results 1 to 2 of 2

Thread: QlistWidget vertical resize to minimum required size

  1. #1
    Join Date
    Feb 2015
    Location
    Cologne/Germany
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QlistWidget vertical resize to minimum required size

    Hey there,

    i am actually having big troubles to get a QListWidget to work, so that it resizes (expands) vertically but to a minimum required size.
    It should adjust if the QListWidget expands horizontally. So, in general it should just request for the space it's childs request. Did try to find a solution for the whole day and the closest i was able to get was this:

    Qt Code:
    1. import sys
    2. from PySide import QtGui, QtCore
    3.  
    4. if __name__ == '__main__':
    5. app = QtGui.QApplication([])
    6.  
    7. window = QtGui.QWidget()
    8. layout = QtGui.QVBoxLayout(window)
    9.  
    10.  
    11.  
    12. list = QtGui.QListWidget()
    13.  
    14. sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
    15. QtGui.QSizePolicy.Ignored)
    16. sizePolicy.setHorizontalStretch(0)
    17. sizePolicy.setVerticalStretch(0)
    18. sizePolicy.setHeightForWidth(list.sizePolicy().hasHeightForWidth())
    19.  
    20. list.setSizePolicy(sizePolicy)
    21. list.setFocusPolicy(QtCore.Qt.NoFocus)
    22. list.setFrameShape(QtGui.QFrame.NoFrame)
    23. list.setLineWidth(0)
    24. list.setAutoScroll(False)
    25. list.setProperty("showDropIndicator", False)
    26. list.setDragDropMode(QtGui.QAbstractItemView.NoDragDrop)
    27. list.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
    28. list.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
    29. list.setMovement(QtGui.QListView.Free)
    30. list.setFlow(QtGui.QListView.LeftToRight)
    31. list.setProperty("isWrapping", True)
    32. list.setResizeMode(QtGui.QListView.Adjust)
    33. list.setLayoutMode(QtGui.QListView.Batched)
    34. list.setViewMode(QtGui.QListView.ListMode)
    35. list.setSelectionRectVisible(True)
    36. list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    37. list.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    38.  
    39. for i in range(2):
    40. item = QtGui.QListWidgetItem()
    41. widget = QtGui.QWidget()
    42.  
    43. widget_layout = QtGui.QHBoxLayout()
    44. edit = QtGui.QLineEdit()
    45. label = QtGui.QLabel("I love PyQt!")
    46. widget_layout.addWidget(label)
    47. widget_layout.addWidget(edit)
    48. widget_layout.addStretch()
    49. widget_layout.setSizeConstraint(QtGui.QLayout.SetFixedSize)
    50. widget.setLayout(widget_layout)
    51. item.setSizeHint(widget.sizeHint())
    52. list.addItem(item)
    53. list.setItemWidget(item, widget)
    54.  
    55.  
    56. list.setFixedSize(list.sizeHintForColumn(0) + 2 * list.frameWidth(), list.sizeHintForRow(0) * list.count() + 2 * list.frameWidth())
    57.  
    58. layout.addWidget(list)
    59. window.show()
    60.  
    61. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    Hope someone can help me here ...

    Thanks,
    René

  2. #2
    Join Date
    Feb 2015
    Location
    Cologne/Germany
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QlistWidget vertical resize to minimum required size

    Hey again,

    i am still stuck with this. I also tried subclassing the QListWidget and use a custom sizeHint() function.
    I really wonder that it works for the horizontal part. I have set the QListWidget to IconMode and Expanding for horizontal.
    It now flows correct with showing as many items in a row as the width allows. but this does not work for the vertical handling.
    This always remains the same.

    I really need some help here ...

    Thanks,
    René

Similar Threads

  1. Minimum required to emit a signal
    By davethomaspilot in forum Newbie
    Replies: 35
    Last Post: 22nd February 2013, 13:56
  2. resize Dialog to minimum height
    By pospiech in forum Qt Programming
    Replies: 7
    Last Post: 25th June 2009, 15:04
  3. Replies: 2
    Last Post: 23rd March 2009, 18:26
  4. Minimum QGroupBox size
    By klnusbaum in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2008, 18:22
  5. QMenuBar minimum size
    By Angelo Moriconi in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 22:14

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.