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()
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()
To copy to clipboard, switch view to plain text mode
in Chip class i set coordinates in this way
def __init__(self,color = "Green", x = 0, y = 0, parent=None):
self.
setPos(QtCore.
QPointF(int(x
),
int(y
))) self.
color = QtGui.
QColor(color
)
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)
To copy to clipboard, switch view to plain text mode
Thanks in advance
Bookmarks