Important: Please read the Qt Code of Conduct -

QGraphicsItem and dragEvents

  • Hey Community,

    I can't get my drag events to work on QGraphicsItem. Even with the setAcceptDrops(True), is there something else to do to enable them ? They work by default on regular widgets...
    Since QGraphicsItems are movable, I understand that it might be a little bit different but can't figure this out.

    here is a sample code :

    from PySide import QtGui, QtCore
    class GraphicItem(QtGui.QGraphicsItem):
        def __init__(self, parent=None):
            super(GraphicItem, self).__init__(parent)
        def boundingRect(self):
            rect = QtCore.QRect(0,0,400,400)
            return rect
        def shape(self):
            path = QtGui.QPainterPath()
            return path
        def paint(self, painter, option, widget):
        def dragEnterEvent(self, event):
            print 'drag enter'
            super(GraphicItem, self).dragEnterEvent(event)
        def dragMoveEvent(self, event):
            print 'drag move'
            super(GraphicItem, self).dragMoveEvent(event)
    s = QtGui.QGraphicsScene()
    v = QtGui.QGraphicsView(s)
    ti = GraphicItem(parent=None)


  • Lifetime Qt Champion


    Do you want to move your items around ?

  • Nope, It is just a static item that it driven by a parent.
    For now I have to do it with mouse press/move/release events + a condition ...
    It works but i feel like the drag events are designed for that.

    Or, am I wrong ?

  • Lifetime Qt Champion

    Then what exactly do you want to achieve using drag and drop ?

Log in to reply