Results 1 to 16 of 16

Thread: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

  1. #1
    Join Date
    Jun 2013
    Location
    Poland, Katowice
    Posts
    13
    Thanks
    1
    Thanked 16 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Hi All
    I have problem with function dropEvent(QGraphicsSceneDragDropEvent *event) when I wanna drop object type QGraphicsItem.
    this is my part code

    QPixmap dwuMasztowiec;
    dwuMasztowiec = QPixmap("../Statki/images/dwu.png");
    statek_1 = scene->addPixmap(dwuMasztowiec);
    statek_1->setPos(277,405);
    statek_1->setFlag(QGraphicsItem::ItemIsMovable);

    I have several objects type statek (statek=ship). I wanna drag this ships somewhere in another place that I can drop and read position this ship.

    I set flag (QGraphicsItem::ItemIsMovable) so I can drag elements but I haven't ideas how drop and read postion ship.

    I used function (which is below) from example robot from Qt but doesn't work


    void Plansza::dropEvent(QGraphicsSceneDragDropEvent *event)
    {
    if (event->mimeData()->hasImage()) {
    dragOver = false;
    pixmap = qVariantValue<QPixmap>(event->mimeData()->imageData());
    update();
    } else {
    Plansza::dropEvent(event);
    }
    }

    If I explained wrong my example , I will tell and show more details.

    I please about support
    Thanks

  2. The following 2 users say thank you to Mariusz_1990 for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Drop is something you drag in from outside the view. What you seem to want is repositioning items per mouse.
    That should already be possible with the Movable flag. Or do you want to drag an item from one view to another?

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:


  5. #3
    Join Date
    Jun 2013
    Location
    Poland, Katowice
    Posts
    13
    Thanks
    1
    Thanked 16 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Exactly I do game in ships and I wanna drag ships on Scene.The drag elements work properly because I added flag (QGraphicsItem::ItemIsMovable). I wanna write function (dropEvent) where I will implement:
    - read postion ships
    - align ships to the grid
    My problem is it that I can't capture event "drop".
    I think that now I explained a little more about my problem

  6. The following 2 users say thank you to Mariusz_1990 for this useful post:


  7. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Have you enabled drop support on the view? I.e. called setAcceptDrops(true)?

    Can you see other drops, e.g. a file list from the file manager?

    Btw, you have an infinite recursion in your code, you are calling the method again in the else branch.

    See also http://qt-project.org/doc/qt-4.8/gra...droprobot.html

    Cheers,
    _

  8. The following 2 users say thank you to anda_skoa for this useful post:


  9. #5
    Join Date
    Jun 2013
    Location
    Poland, Katowice
    Posts
    13
    Thanks
    1
    Thanked 16 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Yes I enabled drop support by function setAcceptDrops(true).
    I saw example with Robot earlier but I don't understand a little this example...
    if I have wrote function dropEvent it I must have also function dragEvent ? or only need to have set flag (QGraphicsItem::ItemIsMovable) ?
    Maybe someone has another example similar to Robot but that elements graphics were load to type QGraphicsItem?

  10. The following 2 users say thank you to Mariusz_1990 for this useful post:


  11. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    dropEvent() should be fine.

    Have you checked if your dropEvent is called by dropping a file list or something else as suggested?

    Item moving is, as I said before, unrelated to drag&drop.

    Cheers,
    _

  12. The following 2 users say thank you to anda_skoa for this useful post:


  13. #7
    Join Date
    Jun 2013
    Location
    Poland, Katowice
    Posts
    13
    Thanks
    1
    Thanked 16 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    I will say truly that I can't check call by dropping a file list or something else...

    this function doesnt working
    void Plansza::dropEvent(QGraphicsSceneDragDropEvent *event)
    {
    if (event->mimeData()->hasImage()) {
    dragOver = false;
    pixmap = qVariantValue<QPixmap>(event->mimeData()->imageData());
    update();
    } else {
    Plansza::dropEvent(event);
    }
    }

    don't capture type QgraphicsItem why??
    Maybe this function work properly but I have to write "connect" where signal will be function dropEvent?

  14. The following 2 users say thank you to Mariusz_1990 for this useful post:


  15. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Quote Originally Posted by Mariusz_1990 View Post
    I will say truly that I can't check call by dropping a file list or something else...
    Why? Do you have no drag enabled program on the machine that you run this on?


    Quote Originally Posted by Mariusz_1990 View Post
    this function doesnt working
    void Plansza::dropEvent(QGraphicsSceneDragDropEvent *event)
    {
    if (event->mimeData()->hasImage()) {
    dragOver = false;
    pixmap = qVariantValue<QPixmap>(event->mimeData()->imageData());
    update();
    } else {
    Plansza::dropEvent(event);
    }
    }
    Is it being called?
    Btw, you still have the infinite recursion in there.


    Quote Originally Posted by Mariusz_1990 View Post
    don't capture type QgraphicsItem why??
    You are checking for image.

    Quote Originally Posted by Mariusz_1990 View Post
    Maybe this function work properly but I have to write "connect" where signal will be function dropEvent?
    No, dropEvent is an event handler method, not a slot.

    Cheers,
    _

  16. The following 2 users say thank you to anda_skoa for this useful post:


  17. #9
    Join Date
    Jun 2013
    Location
    Poland, Katowice
    Posts
    13
    Thanks
    1
    Thanked 16 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Ok I understood a little... but please maybe help me write this function that work properly? I want read ship postion, when ship will drop. I really have not idea that this work work properly...

  18. The following 2 users say thank you to Mariusz_1990 for this useful post:


  19. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Your problem description is too abstract, i.e. there is no indication what your problem actually is.

    Is your dropEvent() method being called? I.e. if you put some qDebug() output in there, so you see that output?
    You can try using a drag from a different application, assuming you have any other program capable of drag&drop running on the same machine. If you run your program on the development machine than it is likely that you have a file manager there.

    Cheers,
    _

  20. The following 2 users say thank you to anda_skoa for this useful post:


  21. #11
    Join Date
    Jun 2013
    Location
    Poland, Katowice
    Posts
    13
    Thanks
    1
    Thanked 16 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Probably We don't understand. How I wrote earlier, I wanna only read postion my ships when I am dropping somewhere on SCENE in my program. I can't drag ships outside SCENE. When I added qDebug() to function dropEvent I didn't see any communique about captured image (ships) by function dropEvent.

  22. The following 2 users say thank you to Mariusz_1990 for this useful post:


  23. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Quote Originally Posted by Mariusz_1990 View Post
    When I added qDebug() to function dropEvent I didn't see any communique about captured image (ships) by function dropEvent.
    Let me rephrase. If you do this:

    Qt Code:
    1. void Plansza::dropEvent(QGraphicsSceneDragDropEvent *event)
    2. {
    3. qDebug() << Q_FUNC_INFO;
    4. }
    To copy to clipboard, switch view to plain text mode 
    do you get that output?
    If not, where does the drag come from, i.e. where does the drag mouse movement start?
    If you drag files from the file manager (assuming the system has a file manager), does the cursor change to indicate that drop is allowed when you move over your view?

    Cheers,
    _

  24. The following 2 users say thank you to anda_skoa for this useful post:


  25. #13
    Join Date
    Jun 2013
    Location
    Poland, Katowice
    Posts
    13
    Thanks
    1
    Thanked 16 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    after added your entry (qDebug() << Q_FUNC_INFO) I still nothing get on the output :/ I start drag element from Scene and want drop also on Scene. When I drag files from the file manager cursor change sign and I can't drop file on the Scene. I have on the Scene 2 board 300px/300px and I want secure second board that someone can't drop ship on her so I need know position ship after drop ship that I can write function which will secure drop on her.

  26. The following 2 users say thank you to Mariusz_1990 for this useful post:


  27. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    Quote Originally Posted by Mariusz_1990 View Post
    after added your entry (qDebug() << Q_FUNC_INFO) I still nothing get on the output :/
    Ok, that is not good. that should have worked for the file drop. Oh, I just had a thought.
    Your dropEvent(), in which class is it? The view or the scene?

    Quote Originally Posted by Mariusz_1990 View Post
    I start drag element from Scene and want drop also on Scene.
    Are those two different scenes or one scene in two different views?

    Cheers,
    _

  28. The following 2 users say thank you to anda_skoa for this useful post:


  29. #15
    Join Date
    Jun 2013
    Location
    Poland, Katowice
    Posts
    13
    Thanks
    1
    Thanked 16 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    I have one scene.
    I attache file statek.pro with my project. Look at this in free moment Statki.zip

  30. The following 2 users say thank you to Mariusz_1990 for this useful post:


  31. #16
    Join Date
    Jun 2013
    Location
    Poland, Katowice
    Posts
    13
    Thanks
    1
    Thanked 16 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: function dropEvent(QGraphicsSceneDragDropEvent *event) doesn't work...

    I will return into question about " Do I need implement function dragEnterEvent,DragMoveEvent?" because I see in documentation QT that they wrote

    void QGraphicsItem::dropEvent ( QGraphicsSceneDragDropEvent * event ) [virtual protected]

    This event handler, for event event, can be reimplemented to receive drop events for this item. Items can only receive drop events if the last drag move event was accepted.

    so How I have interpret this description?

Similar Threads

  1. Replies: 3
    Last Post: 1st May 2013, 20:44
  2. gprof doesn't work
    By soul_rebel in forum Qt Programming
    Replies: 0
    Last Post: 10th May 2012, 14:49
  3. Paint event function in key press event
    By soumya in forum Qt Programming
    Replies: 6
    Last Post: 2nd February 2010, 12:40
  4. dropEvent doesn't happen without mousemove
    By Dimon in forum Qt Programming
    Replies: 0
    Last Post: 6th October 2009, 16:49
  5. qSort doesn't work with member function
    By ber_44 in forum Qt Programming
    Replies: 10
    Last Post: 2nd June 2007, 12:00

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.