PDA

View Full Version : Drag and drop from QTreeWidget to QGraphicsView



igu@na
26th August 2008, 22:38
I've tried to make drag and drop from QTreeWidget to QGraphicsView, but faced with one problem. How to convert correctly coordinates from event->pos() to to QGraphicsView coordinates. The problem is would like to create QGraphicsItem exactly in position where drop event was done, but I can't figure out how to convert event->pos() coordnates to graphics view coordinates



def dropEvent (self, event):
if event.proposedAction() == QtCore.Qt.CopyAction:
if event.source().selectedItems()[0].text(0) == 'Chip':
chip = Chip("green", event.pos().x(), event.pos().y())
self.scene().addItem(chip)
event.accept()


in Chip class i set coordinates in this way


def __init__(self,color = "Green", x = 0, y = 0, parent=None):
QtGui.QGraphicsItem.__init__(self, parent)
self.setPos(QtCore.QPointF(int(x), int(y)))
self.color = QtGui.QColor(color)


Thanks in advance

pherthyl
26th August 2008, 23:19
QPointF QGraphicsView::mapToScene ( const QPoint & point ) const

igu@na
27th August 2008, 08:24
Thanks, now it works much better :cool: