Results 1 to 5 of 5

Thread: A way to detect whether drag is going on

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default A way to detect whether drag is going on

    Is there a way to find out whether a drag operation is going on on top of a widget? It's easy if it's started on that same widget, but if the drag comes from another widget it's not so easy. The drag will be stopped when it's dropped, but I didn't find an easy way to detect whether it has been canceled. It's possible to catch the ESC key event but I think it's not guaranteed to be the only way to cancel drag.

    I have a paint event which does different thing while dragging. The code detecting drag is quite complicated already and it doesn't work reliably.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: A way to detect whether drag is going on

    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: A way to detect whether drag is going on

    I don't know if I wrote unclearly or if you read my post carelessly, but those are not enough. QTreeWidget gets some events which trigger painting (type 43 IIRC, but I can't of course be sure this is the only one), and I should detect whether dragging is going on inside the paint event handler. I have tried to do it with simple boolean flags which are set and unset in some places but they are not completely reliable.

    I think It would work like this:
    - dragEnterEvent -> set dragging flag on
    - dropEvent -> set dragging flag off
    - dropLeaveEvent -> set draggin flag off

    BUT because the drag can be also cancelled, this is not reliable. I would need another event:
    - dragCancelEvent -> set dragging flag off

    Another possibility would be to ask whether drag is going on:
    QApplication::isDragging()
    QWidget::isDragging()

    but there are no such functions.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: A way to detect whether drag is going on

    So do you want to still show some kind of drop indicator even if the drag is currently outside the whole view? QAbstractItemView resets the "hover index" upon:
    • QEvent::HoverLeave
    • QEvent::DragLeave
    J-P Nurmi

  5. #5
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: A way to detect whether drag is going on

    No, I wanted to show an indicator in a widget while the drag is going on on top of that widget. The problem was that I couldn't know in the paintEvent() whether the drag is going on or not because the drag could have been canceled after the state flag had been set and the paintEvent was triggered by some unexpected events.

    Anyways, I found a way to do this. I though I had tested dragLeaveEvent but apparently I hadn't. That event is received also when the drag is canceled. It's not clearly documented so I don't know if I can be 100% sure but this seems to be the correct way to do it. Now it's enough to clear the dragging flag in dragLeave and drop events.

  6. The following user says thank you to eelik for this useful post:

    raven-worx (27th July 2011)

Similar Threads

  1. drag and drop QToolButton in QToolBar
    By NBilal in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:11
  2. Change cursor & status during Drag & Drop
    By ronlongo in forum Qt Programming
    Replies: 0
    Last Post: 1st December 2008, 16:56
  3. Drag & Drop when parent and childs accept drops?
    By gri in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2008, 09:00
  4. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41
  5. Drag 'n Drop problem
    By kiker99 in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2006, 16:35

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.