I am using PySide. I have a QlistWidget that I am populating with icon items. The icons display left to right by default and I would like them to display top to bottom, or have a vertical layout, not a horizontal one. How can I achieve this?
to this:
答案 0 :(得分:2)
您必须将flow
属性设置为QListView::TopToBottom
:
from PySide2 import QtCore, QtGui, QtWidgets
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QListWidget()
w.setViewMode(QtWidgets.QListView.IconMode)
w.setIconSize(QtCore.QSize(128, 128))
w.setResizeMode(QtWidgets.QListView.Adjust)
w.setFlow(QtWidgets.QListView.TopToBottom)
for path in ("icon1.png", "icon2.png"):
it = QtWidgets.QListWidgetItem()
it.setIcon(QtGui.QIcon(path))
w.addItem(it)
w.resize(640, 480)
w.show()
sys.exit(app.exec_())