I did change the dragDropMode
of my QListWidget
to InternalMove
. Now it is possible to change the order of the items via drag and drop.
I now need to execute a function anytime the order of the items is changed.
Therefore, I would like to connect
a signal to one of my functions.
However, I struggle to find the right signal.
I tried many (e.g.: itemChanged
) but so far without luck.
Does somebody know which signal is emitted when I change the item order via drag and drop?
Example: I would like to connect a drag_drop
action to the self.drag_drop_happened()
function.
from PyQt5.QtWidgets import QApplication, QWidget, QListWidget, QVBoxLayout
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.InitWindow()
def InitWindow(self):
self.setWindowTitle("Drag Drop enabled")
vbox= QVBoxLayout()
self.list = QListWidget()
self.list.insertItem(0, "A")
self.list.insertItem(1, "B")
self.list.insertItem(2, "C")
self.list.insertItem(3, "D")
self.list.setDragDropMode(self.list.InternalMove)
vbox.addWidget(self.list)
self.setLayout(vbox)
self.show()
# self.list connect to self.drag_drop_happened()
def drag_drop_happened(self):
pass
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())
self.list.model().rowsMoved.connect(self.drag_drop_happened)
void QAbstractItemModel::rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)