QStyledItemDelegate - implement drag event?
Dariusz last edited by Dariusz
So I've implemented my widget look in QStyledItemDelegate, it has few buttons and lineEdits as "widgets" all hand drawn at the moment.
I would like now to allow for some "dragging" so user can drag on to the "widgets". As far as I can tell there will be 2 drag modes, 1 dragging treeItem itself, 2 dragging widget on to treeItem - custom Widget I draw to perform some action.
I've implemented this in my EditorEvent() function to determine drag start/action, but the second I drag the item "outside" the "treeItem" the treeItem drag operation kick in and my initialized drag appear to be lost... I'm fairly sure I'm doing this in wrong place... any help would be great... some code :
if self.leftPressed: if self.handleDrag(event, option, index) and self.mDragBegin == False: self.mDragBegin = True return True if self.mDragBegin and self.dragInitialized == False: mMouseDragDistance = (event.pos() - self.mMousePressPos).manhattanLength(); print("Drag Distance : ", mMouseDragDistance) if mMouseDragDistance > 4: self.initializeDrag(event, option, index) return True if self.dragInitialized: print("its dragging now!") return True print("we go back to native impl") return super().editorEvent(event, model, option, index) def initializeDrag(self, event, option, index): self.dragInitialized = True print("Drag initialized!") drag = QDrag(self) state = drag.exec_() print("Drag state : ", state)
Dariusz last edited by
It appears that I was almost there... just need to create a proper drag!
def initializeDrag(self, event, option, index): self.dragInitialized = True print("Drag initialized!") drag = QDrag(self) mim = QMimeData() mim.setText("yoyoyooy") drag.setMimeData(mim) val = drag.exec_() print("Return drag val : ", val) self.dragInitialized = False
Once thats made, I then have to handle dragEnterEvent on QTreeView and then pass it to proper function from there... yay!