[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] PyQt4: QGraphicsView/drag&drop problem
From:       Eriol <eriol () mornie ! org>
Date:       2007-06-21 20:33:45
Message-ID: 200706212233.45493.eriol () mornie ! org
[Download RAW message or body]

On Thursday 21 June 2007, Frank Ploss wrote:
> I'm trying to implement drag and drop with a QGraphicsView.

Can't you use the default Graphics View framework drag and drop support 
provided for the scene, and for each item?

----8<----------------------------------

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

class MyItem(QGraphicsRectItem):
    def __init__(self):
        QGraphicsRectItem.__init__(self, QRectF(20, 20, 100, 100))
        self.setFlag(QGraphicsItem.ItemIsMovable)

class MyScene(QGraphicsScene):
    def __init__(self):
        QGraphicsScene.__init__(self)
        self.box = MyItem()
        self.addItem(self.box)

qapp = QApplication(sys.argv)
myScene = MyScene()
myScene.setSceneRect(0, 0, 400, 400)
view = QGraphicsView()
view.setMinimumSize(400, 400)
view.setAcceptDrops(True)
view.setScene(myScene)
view.show()

qapp.exec_()

------>8----------------------------------------

If not, consider that (from the doc: 
http://doc.trolltech.com/4.2/graphicsview.html#drag-and-drop):

To intercept drag and drop events for the scene, you reimplement 
QGraphicsScene::dragEnterEvent() and whichever event handlers your 
particular scene needs, in a QGraphicsItem subclass.

Items can enable drag and drop support by calling 
QGraphicsItem::setAcceptDrops(). To handle the incoming drag, reimplement 
QGraphicsItem::dragEnterEvent(), QGraphicsItem::dragMoveEvent(), 
QGraphicsItem::dragLeaveEvent(), and QGraphicsItem::dropEvent().

HTH,

-- 
 Eriol - *p = NULL; - EIBTI
 GPG Key ID 0B7C8A19
 http://mornie.org
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic