Results 1 to 4 of 4

Thread: Drag and Drop without subclass a widget.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Drag and Drop without subclass a widget.

    Could you please post a pseudo code or suggest an implementation?

  2. #2
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: Drag and Drop without subclass a widget.

    OK, solved. Here is the job I've done:

    Qt Code:
    1. // Form Header (frmSetBackupDir class)
    2.  
    3. // Added
    4. protected:
    5. bool eventFilter(QObject *obj, QEvent *event);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // Form Implementation
    2.  
    3. // Added in the CTOR
    4. ui->lneDirBU->installEventFilter(this);
    5. ui->lneDirBU->setAcceptDrops(true);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. bool frmSetBackupDir::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (event->type() == QEvent::DragEnter)
    4. {
    5. QDragEnterEvent *tDragEnterEvent = static_cast<QDragEnterEvent *>(event);
    6. tDragEnterEvent->acceptProposedAction();
    7.  
    8. return true;
    9. }
    10. else if (event->type() == QEvent::DragMove)
    11. {
    12. QDragMoveEvent *tDragMoveEvent = static_cast<QDragMoveEvent *>(event);
    13. tDragMoveEvent->acceptProposedAction();
    14.  
    15. return true;
    16. }
    17. else if (event->type() == QEvent::Drop)
    18. {
    19. QDropEvent *tDropEvent = static_cast<QDropEvent *>(event);
    20. tDropEvent->acceptProposedAction();
    21.  
    22. qDebug() << "OK, execute your task!";
    23.  
    24. return true;
    25. }
    26. else
    27. {
    28. // standard event processing
    29. return QObject::eventFilter(obj, event);
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

    It seems to work. Better implementations are well accepted!

Similar Threads

  1. Replies: 1
    Last Post: 12th September 2012, 19:26
  2. Drag and drop inside and outside a Widget
    By utopia500 in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 13:42
  3. QListWidgetItem subclass - Crash program in drag/drop
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2009, 09:24
  4. Drag and Drop a widget in and out QTabWidget
    By smarinr in forum Qt Programming
    Replies: 1
    Last Post: 11th December 2008, 19:10
  5. Drag and Drop in a QTreeWidget subclass
    By kishore in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2008, 07:12

Tags for this Thread

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.