Results 1 to 7 of 7

Thread: Drop QGraphicsView/QGraphicsScene big doubt

  1. #1
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Drop QGraphicsView/QGraphicsScene big doubt

    Hi,

    When I do the first drop inside the QGraphicsView everything occurs correctly, but if I tried do another drop is not more accepted. Why this happens?

    I think that the problem is in the "scene" but I don't know the concept behind this.

    Thanks a lot.

    See the code:

    Qt Code:
    1. GraphicsView::GraphicsView( QWidget * parent )
    2. : QGraphicsView(parent)
    3. {
    4. setAcceptDrops(true);
    5. scene = new GraphicsScene;
    6. }
    7.  
    8. GraphicsView::~GraphicsView()
    9. {
    10. delete scene;
    11. }
    12.  
    13. void GraphicsView::dragEnterEvent(QDragEnterEvent *event)
    14. {
    15. event->accept();
    16. }
    17.  
    18. void GraphicsView::dropEvent(QDropEvent *event)
    19. {
    20. if (event->mimeData()->hasFormat("plain/text")) {
    21.  
    22. QByteArray pieceData = event->mimeData()->data("plain/text");
    23. QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
    24. QString string;
    25. dataStream >> string;
    26.  
    27. qDebug() << "drop" << string;
    28.  
    29. setScene(scene);
    30. QFont sansFont("Helvetica [Cronyx]", 12);
    31. scene->addSimpleText(string,sansFont);
    32.  
    33.  
    34. event->setDropAction(Qt::MoveAction);
    35. event->accept();
    36. } else {
    37.  
    38. event->ignore();
    39. }
    40. }
    To copy to clipboard, switch view to plain text mode 

  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: Drop QGraphicsView/QGraphicsScene big doubt

    Why are you setting a new scene in the drop event?

  3. #3
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drop QGraphicsView/QGraphicsScene big doubt

    Hi,

    If I don't use setScene () the text doesn't appear in the view (QGraphicsView).
    As I said, I think that I didn't understood very well the concept yet.

  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: Drop QGraphicsView/QGraphicsScene big doubt

    Did you set the scene on the view as part of setting up the view? From the code you posted I see you haven't. You should do so right after creating the scene. Your problem might be that you are dropping the item outside scene bounds (if you don't explicitly set the scene size it will stretch to encompass all items you place on it) but it's hard to say without knowing more. You should probably be handling the drops in the scene and not in the view, by the way.

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

    vcp (15th April 2010)

  6. #5
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drop QGraphicsView/QGraphicsScene big doubt

    Hi

    I'm going do some tests and I give a feedback so soon be possible.

    Thanks for while.

  7. #6
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drop QGraphicsView/QGraphicsScene big doubt

    Please Wysota,

    Compile my testing code for you to understand better my problem. and perhaps indicate the best way to solve it.

    Download the sources from :ftp.consultecnica.com.br the file dragdrop.zip

  8. #7
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drop QGraphicsView/QGraphicsScene big doubt [SOLVED]

    You should probably be handling the drops in the scene and not in the view, by the way.
    Yes, this was the solution to do drag&drop works.

    Now I understand how QListView and QGraphicsView+QGraphicsScene should work together to that the drag&drop work fine.

Similar Threads

  1. QGraphicsScene & QGraphicsView help please
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 13th February 2017, 12:30
  2. Drag and Drop in QGraphicsScene misses items
    By enno in forum Qt Programming
    Replies: 2
    Last Post: 30th August 2009, 15:17
  3. QGraphicsView and QGraphicsScene
    By alisami in forum Qt Programming
    Replies: 8
    Last Post: 4th December 2008, 10:10
  4. QGraphicsView: Dialog Position Doubt
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2007, 17:48
  5. QGraphicsScene and QGraphicsView
    By rossd in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2007, 14:43

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.