Results 1 to 16 of 16

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 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,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 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,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 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,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 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,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 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:


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
  •  
Qt is a trademark of The Qt Company.