Results 1 to 5 of 5

Thread: Model View Drag Drop to non model view mouse coord offset problem.

  1. #1
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Model View Drag Drop to non model view mouse coord offset problem.

    I have a QTreeView with QStandardItems. I have a sub-classed QWigget that will accept drops from the QTreeView. It works great except for one annoying bug.
    When the item is dragged over the drop widget, then released, it is not placed where it is dropped, only nearby. This is because I do not know the mouse point within the delegate that is being dragged. If I knew it, I could have it drop right where the user intended it. Instead they have to drop it and reposition it.

    How can I get the mouse offset within the delegate, so that it is drag-and-drop-once?

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Model View Drag Drop to non model view mouse coord offset problem.

    You could implement QWidget::dropEvent() in the widget accepting the drop and tell the delegate drop coordinates there.

    On another hand, why the delegate needs to know the position?
    It should be the accepting widget that is interested in what is dropped and where.

  3. #3
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Model View Drag Drop to non model view mouse coord offset problem.

    Yes, absolutely true. I have implemented dropEvent on the widget accepting the drop.

    And yes, the delegate does not need to know, but the accepting widget does. However, I'm still at a loss of how to get the mouse location offset within the delegate.

    However I cannot figure out for the life of me, how to get the mouse location in the delgate. Currently, the drop happens, but the mouse coords are the mouse coords. Using these, the dropped item is off by however much the x,y offset is of the mouse in the delegate. That is to say given a 50x100 delegate, if I click and drag in the middle, the drop location is off by 25,50. I need to get that offset and subtract that from the mouse coords to get a "perfect drop"

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Model View Drag Drop to non model view mouse coord offset problem.

    Hmmmm I don't quite follow.

    The drop position should be where the mouse was released.
    If the coordinates that are in the drop event are wrong, try using QCursor:os().

    It's late and I'm tired today, but if you get a compilable example of your issue I (or maybe someone else) can take a look at it.

  5. #5
    Join Date
    Apr 2008
    Posts
    45
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Model View Drag Drop to non model view mouse coord offset problem.

    Here, let me make a picture
    +--------------+
    |---deleg.te---|
    +--------------+

    Now the "." in the delegate is the mouse location. When I drop this delegate on the widget, I get the location of the "." in the widget coordinates. The problem is, if I put an item at that location it is off by
    +--------
    |---deleg

    So I need to subtract (10,2 - in characters) from the "." position(10,2) to get the proper place in the widget to position the item. This is the offset I am looking for.

    If the mouse were at 0,0 in t he delegate, I would be all set. But it never is.

Similar Threads

  1. Drag & drop with model/view (Qt4)
    By yogeshm02 in forum Qt Programming
    Replies: 16
    Last Post: 19th September 2011, 21:36
  2. Replies: 0
    Last Post: 21st April 2010, 13:23
  3. Replies: 1
    Last Post: 1st February 2010, 19:42
  4. QSql Model-View: How to keep view in sync with model
    By schall_l in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2008, 00:31
  5. Replies: 1
    Last Post: 30th November 2007, 12:55

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.