[英]How can I have the icon items in my QlistWidget insert into the widget, or display, from top to bottom and not left to right?
I am using PySide.我正在使用 PySide。 I have a QlistWidget that I am populating with icon items.
我有一个 QlistWidget,我正在用图标项填充它。 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:对此:
You have to set the flow
property to QListView::TopToBottom
:您必须将
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_())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.