Results 1 to 5 of 5

Thread: Set QDrag mimeData

  1. #1
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    1
    Qt products
    Qt5

    Default Set QDrag mimeData

    I have a class derived from QTableWidget, receiving drag'n'drop from external files and displays the name. The default action is Qt::CopyAction, and to ensure that the action to be performed is Qt::LinkAction, I must use drag->exec(Qt::LinkAction).

    Qt Code:
    1. void tableWidget::dropEvent(QDropEvent *event) {
    2. //…
    3. QDrag *drag = new QDrag(this);
    4. //…
    5. }
    To copy to clipboard, switch view to plain text mode 

    Since
    Qt Code:
    1. event->mimeData()
    To copy to clipboard, switch view to plain text mode 
    returns data as const QMimeData and drag->setMimeData(data) accept argument as QMimeData, there is a way to overcome this problem?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Set QDrag mimeData

    Quote Originally Posted by Imhotep View Post
    I have a class derived from QTableWidget, receiving drag'n'drop from external files and displays the name. The default action is Qt::CopyAction, and to ensure that the action to be performed is Qt::LinkAction, I must use drag->exec(Qt::LinkAction).
    QDrag::exec() starts a new drag operation.
    Are you sure you want to do that?

    Your description sounds like you want the incoming drag to perform the LinkAction.
    See QDropEvent::setDropAction() for doing that.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    1
    Qt products
    Qt5

    Default Re: Set QDrag mimeData

    Tried this

    Qt Code:
    1. void DTableWidget::dropEvent(QDropEvent *event) {
    2. event->setDropAction(Qt::LinkAction);
    3. event->accept();
    4. //…
    5. }
    To copy to clipboard, switch view to plain text mode 

    Still perform Qt::CopyAction

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Set QDrag mimeData

    Have you checked if the LinkAction is part of the QDropEvent::possibleActions() list?

    It could very well be that the drag's source does not support that.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    1
    Qt products
    Qt5

    Default Re: Set QDrag mimeData

    Seems to be

    Qt Code:
    1. void DTableWidget::dropEvent(QDropEvent *event) {
    2. qDebug() << event->possibleActions();
    3. event->setDropAction(Qt::LinkAction);
    4. event->accept();
    5. //…
    6. }
    To copy to clipboard, switch view to plain text mode 

    QFlags<Qt::DropAction>(CopyAction|MoveAction|LinkA ction)

Similar Threads

  1. use custom mimedata between two windows
    By prasad_N in forum Qt Programming
    Replies: 20
    Last Post: 10th March 2016, 14:06
  2. Replies: 15
    Last Post: 18th February 2016, 09:19
  3. When does Mimedata() get called?
    By TEAmerc in forum Newbie
    Replies: 4
    Last Post: 13th October 2015, 15:58
  4. Itemview D&D mimeData
    By chocolate in forum Qt Programming
    Replies: 6
    Last Post: 19th March 2009, 15:44
  5. Drag and Drop MimeData
    By Zephro in forum Qt Programming
    Replies: 10
    Last Post: 16th May 2006, 19:20

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