Results 1 to 5 of 5

Thread: Drag and drop Items in QGraphicsScene

  1. #1
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Drag and drop Items in QGraphicsScene

    Hi guys,
    I have a number of image items (QGraphicsPixmapItem) which are arranged in rows and columns in QGraphicsScene. I want to implement something like when drag an image item, that image will be dropped at the end and the following images will move forwards (replace the moved image).
    I found the similar example, but it implements in QListWidget. And I dont know how to implement it in QgraphicsScene.
    http://qt-project.org/doc/qt-5/qtwid...e-example.html
    Does anybody have any idea how to do that?
    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and drop Items in QGraphicsScene

    Reimplement mouse events for the scene and handle all the logic there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Drag and drop Items in QGraphicsScene

    Yeah, I reimplement these events:
    - mousePressEvent for the QGraphicsPixmapItem: to store the selected item's data (location and pixmap) and create QDrag
    - dragEnterEvent, dragMoveEvent, and dropEvent for the QGraphicsScene: in dropEvent, retrieve the item's data and add the item into the scene.
    The problem is how to update location of image items in the scene: selected item goes to end, following items go forwards. Any suggestions?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and drop Items in QGraphicsScene

    Don't reimplement drag events. Reimplement mouse events only -- mousePress, mouseMove and mouseRelease events. You don't need anything else. To be honest you can do even without reimplementing those events but instead handling itemChanged() but if you don't have experience with that, it might be easier with mouse events.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    MinMin (27th March 2014)

  6. #5
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Drag and drop Items in QGraphicsScene

    Thank you for your advice I will try and see how

Similar Threads

  1. Help with drag and drop several items, labels
    By jimmybanegas93 in forum Qt Programming
    Replies: 1
    Last Post: 14th February 2014, 08:41
  2. Drag&Drop using QGraphicsScene
    By topcraft in forum Qt Programming
    Replies: 0
    Last Post: 24th October 2011, 13:46
  3. drag&drop from QGraphicsScene to QListWidget
    By hakiim35 in forum Qt Programming
    Replies: 4
    Last Post: 7th July 2010, 11:29
  4. Drag and Drop in QGraphicsScene misses items
    By enno in forum Qt Programming
    Replies: 2
    Last Post: 30th August 2009, 15:17
  5. Drag & drop items on the same QTreeView
    By wind in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2006, 14:29

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.