Results 1 to 4 of 4

Thread: Drop item from view outside the window

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Posts
    79
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Drop item from view outside the window

    I have application with QTreeView which contents an image of remote file system (webdav) and QTreeView contents local file system.
    I want to implement drag'n'drop actions for my app.
    It works perfectly when i move items between my app's widgets or from outside my app. in QAbstractItemModel::dropMimeData i can control all activity. It looks like that:

    Qt Code:
    1. bool MyModel::dropMimeData (const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent)
    2. {
    3. QList<QUrl> urls = data->urls();
    4. foreach(const QUrl url,urls)
    5. {
    6. LocalFileItem * item = static_cast<RemoteFileItem *>(parent.internalPointer());
    7. if(url.scheme() == "file")
    8. copeLocalFile(item,url);
    9. // url looks like dav:///public/test.txt
    10. else if(url.scheme() == "dav")
    11. {
    12. QString remoteFile = url.path();
    13. copyRemoteFile(remoteFile,item);
    14. }
    15. }
    16. return false;
    17. }
    To copy to clipboard, switch view to plain text mode 

    It also works good when I copy file from local tree to the desktop, or even to another place outside my app. I just set correct url like that:

    Qt Code:
    1. QMimeData * MyModel::mimeData (const QModelIndexList & indexes) const
    2. {
    3. QMimeData * mimeData = new QMimeData();
    4. QList<QUrl> urls;
    5. foreach (const QModelIndex index, indexes)
    6. {
    7. if (index.isValid())
    8. {
    9. FileItem * item = static_cast<FileItem*>(index.internalPointer());
    10. urls.append(item.url()); // url looks like file://c://test.txt
    11. }
    12. }
    13. mimeData->setUrls(urls);
    14. return mimeData;
    15. }
    16. QStringList MyModel::mimeTypes() const
    17. {
    18. QStringList types;
    19. types << "text/uri-list";
    20. return types;
    21. }
    To copy to clipboard, switch view to plain text mode 

    But the problem is to copy from remote tree to desktop. All drop actions are controlled by OS. So I cannot handle the moment when my item actually was dropped.
    It should be noted that coppied file not exists in local file system while dropping.

    I have an idea how to solve this problem:

    reimplement QMimeData and method retrieveData() like that:
    Qt Code:
    1. QVariant MimeData::retrieveData (const QString & mimeType, QVariant::Type type) const
    2. {
    3. //Qt::MouseButtons buttons = QApplication::mouseButtons ();
    4. // here i need check if mouse buttom was release(item was dropped), create temporary file, copy content of remote file into temp file and return path to this file;
    5. return QMimeData::retrieveData(mimeType,type);
    6. }
    To copy to clipboard, switch view to plain text mode 
    but I cannot find the way to get state of mouse button, QApplication::mouseButtons does not returns actual state.

    Any other ideas?
    Last edited by folibis; 15th June 2012 at 05:45.

Similar Threads

  1. Replies: 0
    Last Post: 7th January 2012, 15:20
  2. Drag and Drop file into Qt Quick window
    By marwooj in forum Qt Quick
    Replies: 0
    Last Post: 23rd June 2011, 04:04
  3. Replies: 2
    Last Post: 13th October 2010, 21:51
  4. Replies: 0
    Last Post: 4th May 2010, 10:24
  5. Preventing drop/drag outside the main window
    By ucomesdag in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2007, 10:42

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.