Results 1 to 5 of 5

Thread: Getting DragEvent target info

Hybrid View

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

    Default Re: Getting DragEvent target info

    One option would be to handle drag and drop events by installing an event filter on children.

    Qt Code:
    1. bool Parent::eventFilter(QObject* receiver, QEvent* event)
    2. {
    3. DraggableLED* led = dynamic_cast<DraggableLED*>(receiver);
    4. if (!led)
    5. return false; // not a DraggableLED
    6.  
    7. switch (event->type())
    8. {
    9. case QEvent::DragEnter:
    10. // do something with led
    11. break;
    12. ...
    13. }
    14. return false;
    15. }
    To copy to clipboard, switch view to plain text mode 

    The difference with reimplementing such event handler of the parent is that by the time event reaches parent it has already been ignored by the child:
    Qt Code:
    1. void Parent::dragEnterEvent(..)
    2. {
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  2. #2
    Join Date
    Mar 2007
    Posts
    74
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting DragEvent target info

    Unfortunately the child doesn't have enough info to complete the task. Only the parent
    has that. I don't want some kludge like a pointer back to the parent. Seems like there
    should be a way to do it.

    Can't I somehow get access to the target widget from the coordinates of the
    drop point event->pos()?

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

    Default Re: Getting DragEvent target info

    Quote Originally Posted by MrGarbage View Post
    Unfortunately the child doesn't have enough info to complete the task. Only the parent has that.
    That's exactly why I made the "Parent" being an event filter.
    J-P Nurmi

  4. #4
    Join Date
    Mar 2007
    Posts
    74
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting DragEvent target info

    I found a solution for this.

    QWidget *child = childAt(event->pos());
    DraggableLED *target = static_cast<DraggableLED*>(child->parentWidget());

    Thanks for your input!

Similar Threads

  1. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  2. Qtopia host side development environment for ARM target.
    By hvreddy1110 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 11th October 2006, 15:05
  3. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23

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.