Results 1 to 3 of 3

Thread: Drag and drop from QTreeWidget to QGraphicsView

  1. #1
    Join Date
    Aug 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Drag and drop from QTreeWidget to QGraphicsView

    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

    Qt Code:
    1. def dropEvent (self, event):
    2. if event.proposedAction() == QtCore.Qt.CopyAction:
    3. if event.source().selectedItems()[0].text(0) == 'Chip':
    4. chip = Chip("green", event.pos().x(), event.pos().y())
    5. self.scene().addItem(chip)
    6. event.accept()
    To copy to clipboard, switch view to plain text mode 

    in Chip class i set coordinates in this way
    Qt Code:
    1. def __init__(self,color = "Green", x = 0, y = 0, parent=None):
    2. QtGui.QGraphicsItem.__init__(self, parent)
    3. self.setPos(QtCore.QPointF(int(x), int(y)))
    4. self.color = QtGui.QColor(color)
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance

  2. #2
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag and drop from QTreeWidget to QGraphicsView

    Qt Code:
    1. QPointF QGraphicsView::mapToScene ( const QPoint & point ) const
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag and drop from QTreeWidget to QGraphicsView

    Thanks, now it works much better

Similar Threads

  1. QTreeWidget Drag and drop
    By zell99 in forum Newbie
    Replies: 15
    Last Post: 7th August 2010, 13:28
  2. QTreeWidget Drag and Drop
    By tommydent in forum Qt Programming
    Replies: 10
    Last Post: 25th August 2008, 15:25
  3. Drag and Drop item inside QTreeWidget
    By nina1983 in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2008, 11:43
  4. Drag and Drop in a QTreeWidget subclass
    By kishore in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2008, 07:12
  5. Drag an item from QTreeWidget and drop in TableView
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2007, 11:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.