简体   繁体   English

如何将 QlistWidget 中的图标项从上到下而不是从左到右插入小部件或显示?

[英]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?我怎样才能做到这一点?

from 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.

相关问题 如何从左到右和从上到下对轮廓进行排序? - How can I sort contours from left to right and top to bottom? 如何以一致的方式从左到右和从上到下对轮廓进行排序 - How can I sort contours from left to right and top to bottom in a consistent manner Python:使用 OpenCV 从左上角到右下角对项目进行排序 - Python: Sorting items from top left to bottom right with OpenCV QListWidget:如何拖放插入带有图标的自定义小部件? - QListWidget: How to drag and drop insert custom widget w/ icon? 如何将列表中的项目插入 QlistWidget? - How to insert Items from a list into QlistWidget? 如何在 Seaborn 的配对图中绘制右轴和上轴并移除左轴和下轴? - How can I draw the right and top axis and remove the left and bottom axis in a Pairplot of Seaborn? 如何提取图像中白色蒙版(多边形)的坐标(上、下、左、右)? - How can i extract out the coordinates (top, bottom, left, right) of white mask (polygon) in image? 如何从左上方到右下方订购坐标? - How to order coordinates from top left to bottom right? 如何在右上角显示时间和日期,同时在左上角显示温度? - How can I get the Temperature to display in the top left corner while having the time and date in the top right? 如何按点的 x 和 y 坐标对点进行排序,以便它们从上到下、从左到右排序? - How do I sort points by their x and y coordinates so that they are ordered from top to bottom, left to right?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM