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:
Code:
import sys
from PySide import QtGui, QtCore
if __name__ == '__main__':
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(list.sizePolicy().hasHeightForWidth())
list.setSizePolicy(sizePolicy)
list.setFocusPolicy(QtCore.Qt.NoFocus)
list.
setFrameShape(QtGui.
QFrame.
NoFrame) list.setLineWidth(0)
list.setAutoScroll(False)
list.setProperty("showDropIndicator", False)
list.setProperty("isWrapping", True)
list.setSelectionRectVisible(True)
list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
list.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
for i in range(2):
label
= QtGui.
QLabel("I love PyQt!") widget_layout.addWidget(label)
widget_layout.addWidget(edit)
widget_layout.addStretch()
widget_layout.
setSizeConstraint(QtGui.
QLayout.
SetFixedSize) widget.setLayout(widget_layout)
item.setSizeHint(widget.sizeHint())
list.addItem(item)
list.setItemWidget(item, widget)
list.setFixedSize(list.sizeHintForColumn(0) + 2 * list.frameWidth(), list.sizeHintForRow(0) * list.count() + 2 * list.frameWidth())
layout.addWidget(list)
window.show()
sys.exit(app.exec_())
Hope someone can help me here ...
Thanks,
René
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é