Results 1 to 5 of 5

Thread: Getting DragEvent target info

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

    Default Getting DragEvent target info

    Hi,

    I am implementing a Drag and Drop of some LED objects.
    These are embedded in some layouts which are part of a config class where
    I am implementing the dragEnterEvent(), etc.

    Im my LED objects' mousePressEvent() I setup QMimeData such that in my
    config class dropEvent() I successfully decode the mime data that I passed in.

    So I have all of the info about the source widget...

    The problem is that I need some information about the target widget in
    order to determine if I will actually allow the drop and what to do
    with the source mime data.

    There doesn't seem to be a way to find the target widget.
    I have event->pos but I don't seem to be able to get this to
    map to the widget where I am dropping.

    This seems like it should do it, but the result is not the target object.
    DraggableLED *child = static_cast<DraggableLED*>(childAt(event->pos()));

    Many thanks

    Mark

  2. #2
    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

  3. #3
    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()?

  4. #4
    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

  5. #5
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.