Drag&Dropping last index item of a QListWidget removes its contents
-
Hello, this is my setup:
# essential bits class DropOffArea(QListWidget): def __init__(self): super().__init__() self.setSelectionMode(QListWidget.ExtendedSelection) self.setLayoutMode(QListWidget.SinglePass) self.setFlow(QListWidget.LeftToRight) self.setDragDropMode(QListWidget.InternalMove) # QWidget subclass, contains buttons and sliders item1 = LightPanelWidget(hou.node('/obj/rslight1'), parent=self) list_item1 = QListWidgetItem() list_item1.setSizeHint(QSize(90, 100)) self.addItem(list_item1) self.setItemWidget(list_item1, item1)
The default dragdrop mode works like an absolute charm except when I drag&drop the last item beyond itself, then it loses the widgets. Works fine if the dragged item isn't last.
Is this expected and what can I try to resolve this?
-
@alexmaje
There are quite a few hits for this if you GoogleQListWidget.InternalMove
. https://stackoverflow.com/questions/30291628/internalmove-in-qlistwidget-makes-item-disappear suggestssetDefaultDropAction(Qt::TargetMoveAction); #if QT_VERSION >= QT_VERSION_CHECK(5,10,0) myList->setMovement(QListView::Free); #endif
Does this make it not disappear for you?
Then see also possible https://forum.qt.io/topic/143860/qlistwidget-drag-drop-item-disappear
-
@JonB I wasn't even aware my widgets would disappear when dragging it in the middle like that -- but they did as well!
The second link seems to have solved it. Thank you so much for help!
Just in case anyone finds this in the future, here's the Python version:
def dragMoveEvent(self, e): if ( (self.row(self.itemAt(e.pos())) == self.currentRow() + 1) or (self.currentRow() == self.count() - 1 and self.row(self.itemAt(e.pos())) == -1) ): e.ignore() else: super().dragMoveEvent(e)
-