Results 1 to 4 of 4

Thread: Drop item from view outside the window

  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.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drop item from view outside the window

    QApplication::mouseButtons does not returns actual state.

    please explain.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drop item from view outside the window

    I don't see how doing anything with QMimeData is going to help you handle drops on areas not belonging to you. Your MIME object will simply be ignored if you drop the drag on a foreign area and that area doesn't want to handle your drop.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: Drop item from view outside the window

    Quote Originally Posted by amleto View Post
    QApplication::mouseButtons does not returns actual state.

    please explain.
    At the beginning of the drag operation QApplication::mouseButtons return Qt::LeftButton and it is OK. when you release the button (item dropped) it still returns
    Qt::LeftButton. Even if you press right button while moving dragged item it still returns Qt::LeftButton.


    Added after 20 minutes:


    Quote Originally Posted by wysota View Post
    I don't see how doing anything with QMimeData is going to help you handle drops on areas not belonging to you.
    I used my own class inherited from QMimeData. So I found that retrieveData was called every time when dragged object was moved over desktop or folder and files at the desktop. Even when this object was dropped on the desktop this function was called. That exactly wat I need. In order to mark out the drop action I check state of left button.
    But it is not works as was described above.

    Quote Originally Posted by wysota View Post
    Your MIME object will simply be ignored if you drop the drag on a foreign area and that area doesn't want to handle your drop.
    I provide correct MIME type (text/uri-list) and correct MIME data(for example file://c:/test.txt) so my obect will be accepted for drop
    Last edited by folibis; 15th June 2012 at 11:37.

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.