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:
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_())
import sys
from PySide import QtGui, QtCore
if __name__ == '__main__':
app = QtGui.QApplication([])
window = QtGui.QWidget()
layout = QtGui.QVBoxLayout(window)
list = QtGui.QListWidget()
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Ignored)
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.setDragDropMode(QtGui.QAbstractItemView.NoDragDrop)
list.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
list.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
list.setMovement(QtGui.QListView.Free)
list.setFlow(QtGui.QListView.LeftToRight)
list.setProperty("isWrapping", True)
list.setResizeMode(QtGui.QListView.Adjust)
list.setLayoutMode(QtGui.QListView.Batched)
list.setViewMode(QtGui.QListView.ListMode)
list.setSelectionRectVisible(True)
list.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
list.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
for i in range(2):
item = QtGui.QListWidgetItem()
widget = QtGui.QWidget()
widget_layout = QtGui.QHBoxLayout()
edit = QtGui.QLineEdit()
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_())
To copy to clipboard, switch view to plain text mode
Hope someone can help me here ...
Thanks,
René
Bookmarks