prashant
27th September 2009, 17:24
Hi,
Task:
Drag item from QTreeWidget and drop it to QGraphicsView
Here is the property set up and function to start the drag in QTreeWidget.
I am not using any more function except this one:
....
#
self.setDragEnabled(True)
self.setHeaderHidden(True)
self.setColumnCount(1)
self.setFocusPolicy(QtCore.Qt.NoFocus)
def startDrag(self, supportedActions):
print self.currentItem().text(0)
currentItemName = self.currentItem().text(0)
mimeData = QtCore.QMimeData()
mimeData.setText(currentItemName)
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
dropAction = drag.start(QtCore.Qt.CopyAction)
Here is the property set up and function for dropping in QGraphicsView.
I am using only two functions here:
....
self.setScene(QxScene(self))
self.setCacheMode(QtGui.QGraphicsView.CacheBackgro und)
self.setRenderHint(QtGui.QPainter.Antialiasing, 1)
self.setDragMode(QtGui.QGraphicsView.RubberBandDra g)
self.setOptimizationFlags(QtGui.QGraphicsView.Dont SavePainterState)
self.setViewportUpdateMode(QtGui.QGraphicsView.Sma rtViewportUpdate)
self.setBackgroundBrush(QtCore.Qt.lightGray)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasText():
event.acceptProposedAction()
print "enter accepted"
else:
print "enter ignore"
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasText():
xmlFileName = event.mimeData().text()
position = event.pos()
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
print xmlFileName, position
else:
print "drop ignore"
event.ignore()
As soon as mouse is entering in QGraphicsView, message "event accepted" is getting printed in function "dragEnterEvent".
Problem is that cursor is still forbidden cursor and I can't drop.
Cheers
Prashant
Python 2.5.2
PyQt-Py2.5-gpl-4.4.3-1
Win XP, 32 Bit
Task:
Drag item from QTreeWidget and drop it to QGraphicsView
Here is the property set up and function to start the drag in QTreeWidget.
I am not using any more function except this one:
....
#
self.setDragEnabled(True)
self.setHeaderHidden(True)
self.setColumnCount(1)
self.setFocusPolicy(QtCore.Qt.NoFocus)
def startDrag(self, supportedActions):
print self.currentItem().text(0)
currentItemName = self.currentItem().text(0)
mimeData = QtCore.QMimeData()
mimeData.setText(currentItemName)
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
dropAction = drag.start(QtCore.Qt.CopyAction)
Here is the property set up and function for dropping in QGraphicsView.
I am using only two functions here:
....
self.setScene(QxScene(self))
self.setCacheMode(QtGui.QGraphicsView.CacheBackgro und)
self.setRenderHint(QtGui.QPainter.Antialiasing, 1)
self.setDragMode(QtGui.QGraphicsView.RubberBandDra g)
self.setOptimizationFlags(QtGui.QGraphicsView.Dont SavePainterState)
self.setViewportUpdateMode(QtGui.QGraphicsView.Sma rtViewportUpdate)
self.setBackgroundBrush(QtCore.Qt.lightGray)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasText():
event.acceptProposedAction()
print "enter accepted"
else:
print "enter ignore"
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasText():
xmlFileName = event.mimeData().text()
position = event.pos()
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
print xmlFileName, position
else:
print "drop ignore"
event.ignore()
As soon as mouse is entering in QGraphicsView, message "event accepted" is getting printed in function "dragEnterEvent".
Problem is that cursor is still forbidden cursor and I can't drop.
Cheers
Prashant
Python 2.5.2
PyQt-Py2.5-gpl-4.4.3-1
Win XP, 32 Bit