PyQt: How to get most of QListWidget

余生长醉 提交于 2019-11-30 14:20:33

List-widget items can be moved up and down via drag and drop, but it is not enabled by default. To switch it on, do this:

    self.listWidget.setDragDropMode(QtGui.QAbstractItemView.InternalMove)

Multiple-selection is one of several selection-modes available. To switch it on, do this:

    self.listWidget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)

Sorting is disabled by default. To switch it on, do this:

    self.listWidget.setSortingEnabled(True)

To re-sort the list, do one of these:

    self.listWidget.sortItems() # ascending by default
    self.listWidget.sortItems(QtCore.Qt.DescendingOrder)

Sorting is alphabetical and case-insensitive by default. If you want a custom sort-order, subclass QListWidgetItem and re-implement its less-than operator:

class ListWidgetItem(QtGui.QListWidgetItem):
    def __lt__(self, other):
        return self.text() < other.text() # or whatever
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!