Results 1 to 14 of 14

Thread: drag-drop question

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default drag-drop question

    Hi,

    I want to ask how can I make a graphic item drag and drop through on a certain line?

    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-drop question

    What do you mean by "through on a certain line"?
    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
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: drag-drop question

    Hi,

    I wanted to mean along a certain line. In other words, whereever I drag my item in the view, I want it to move along a certain line according to the dragging movements.

  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-drop question

    In that case you probably want not "dragging" but "moving". You can either reimplement mouseMoveEvent() or itemChange() for the item. Both will allow you to control the position of the item when it is moved with the mouse.
    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. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: drag-drop question

    Hi ,

    I see but for example what if I want to move the item in x axis with a restricted range let's say between x = 10 and x = -20 ?

  6. #6
    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-drop question

    Read the docs of QGraphicsItem::itemChange()
    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.


  7. #7
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: drag-drop question

    I know that and I already read the docs. I try to look at docs before I send threads here.

    Anyway, this is ok for rectangular shapes but what I want to really achieve is shapes like polygons or circle.

    I think I need something like "closest point" to the shape when I make my item move on the shape in order to keep the item's position on the regarding shape.

    Thanks in advance

  8. #8
    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-drop question

    You can use any math calculations you want. The shape doesn't matter. Remember you always have the boundingRect() you can work with.
    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.


  9. #9
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: drag-drop question

    Hi again,

    But if we can only play with the bounding rectangle, how can we perform this movement on a polygon since the bounding rectangle always returns a QRectF?

    I will be pleased if you can give me more tips about it.

    Thanks in advance

  10. #10
    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-drop question

    I don't understand the problem. Could you elaborate?
    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.


  11. #11
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: drag-drop question

    Sorry for the late answer first,

    Yes I can. First of all, think I have a polygonal path for the mouse to be moved on the view. Then please see the following shape I've sent.

    In this shape 1,2 and 3 are the example valid mouse locations. Suppose that the white background is the view(or scene) and the polygonal path is the path that the mouse can only move on.
    Attached Images Attached Images
    Last edited by zgulser; 6th July 2009 at 13:48.

  12. #12
    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-drop question

    I really don't see what is so problematic. Did you try using itemChange() as I told you? You can check there if the new position of the item is on the polyline and if not, snap it to the desired position. The fact that the example uses a rectangular area doesn't mean you can only snap to rectangular areas.
    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.


  13. #13
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: drag-drop question

    Hi again,

    I'm of course using itemChange method. But the problematic case is about the snapping. I couldn't figure out how to snap actually. That's why I said I need a closest point to my polygonal path to snap in one of my previous posts in this thread. What should I do in order to catch the correct snap position when the mouse moves?

  14. #14
    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-drop question

    Either do maths manually (the formula is not complicated) and/or use what QLineF offers. In general you need to find a line that is perpendicular to the closest component of the polyline that goes through the point of the current position of the item and then find the intersection of the original line and the perpendicular and the result will be the desired position of the item.

    Of course you can just cheat and find two points - one that has the same horizontal coordinate as the current point and lies on the desired line, the other that has the same vertical coordinate as the current point and lies on the desired line and then compare the points to the current point and pick the one that is closer to the current point as the new point of the item.

    You will still need to detect which component of the polyline is the closest to the current point.

    Edit: here is a diagram to illustrate
    Attached Images Attached Images
    Last edited by wysota; 6th July 2009 at 15:09.
    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.


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

    zgulser (7th July 2009)

Similar Threads

  1. Drag and Drop QTableWidget in UI file.
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 20th January 2009, 23:02
  2. drag and drop QToolButton in QToolBar
    By NBilal in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:11
  3. Change cursor & status during Drag & Drop
    By ronlongo in forum Qt Programming
    Replies: 0
    Last Post: 1st December 2008, 16:56
  4. Drag n Drop question
    By Ashitaka in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2006, 07:21
  5. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41

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.