QListWidget
наследуется от QAbstractItemView
. Вы можете использовать QAbstractItemView.setDragDropMode()
и установить его на QAbstractItemView.InternalMove
, если хотите, чтобы вы могли изменить порядок своих товаров с помощью перетаскивания &.
Here's the relevent section of the documentation.
Вот краткий пример, показывающий его в действии:
import sys
from PyQt4.QtGui import QApplication, QWidget, \
QVBoxLayout, QListWidget, QAbstractItemView
class Widget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.widget_layout = QVBoxLayout()
# Create ListWidget and add 10 items to move around.
self.list_widget = QListWidget()
for x in range(1, 11):
self.list_widget.addItem('Item {:02d}'.format(x))
# Enable drag & drop ordering of items.
self.list_widget.setDragDropMode(QAbstractItemView.InternalMove)
self.widget_layout.addWidget(self.list_widget)
self.setLayout(self.widget_layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = Widget()
widget.show()
sys.exit(app.exec_())
Причина -1: вопрос должен разъяснить вам с помощью кода из QtDesigner и отбраковать вниз к короткому самодостаточного, например, чтобы перейти от. Поскольку так мало деталей было указано, и никакого кода, никаких подробностей вашего рабочего процесса, ответ от Гэри Хьюза, скорее всего, не поможет вам. – neuronet