how to Drag&Drop a file from windows(eg.Window Resource Manager) into QTreeWidget?



  • how to Drag&Drop a file from windows(eg.Window Resource Manager) into QTreeWidget?
    when the mouse realease(ie. drop) on a QTreeWidgetItem, the file will added into the related Dir.


  • Lifetime Qt Champion

    Hi,

    Start by having a look at the Drag & Drop documentation



  • i know how to darg beteen widget. but i don't know how can i
    how to Drag&Drop a file from windows(eg.Window Resource Manager) into QTreeWidget?



  • @opengpu2 You can find good example "Drop site example" in QtCreator. You know how to read? Read again documentation please:

    Interoperating with Other Applications

    On X11, the public XDND protocol is used, while on Windows Qt uses the OLE standard, and Qt for OS X uses the Cocoa Drag Manager. On X11, XDND uses MIME, so no translation is necessary. The Qt API is the same regardless of the platform. On Windows, MIME-aware applications can communicate by using clipboard format names that are MIME types. Already some Windows applications use MIME naming conventions for their clipboard formats.

    Custom classes for translating proprietary clipboard formats can be registered by reimplementing QWinMime on Windows or QMacPasteboardMime on OS X.



  • @SGaist
    i saw the link, and i found it doesnot use ::strartDrag.
    and as i saw in the Qt examples, i saw ::startDrag is used somewhere.
    which way is better? use the ::startDrag or not(then use ::mousePress,etc...)



  • and i noticed: i have to add drag->exec(); int the ::startDrag.
    as i search all the examples, i found drag->exec(); can be in (1)::startDrag, (2)::mousePress, (3)::mouseMove.......what is the different?

    and i found code like this:
    Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
    i don't quite understand the meaning of Qt::DropAction...
    as there can be if (drag->exec(Qt::MoveAction) == Qt::MoveAction) {......}
    what does it mean?


  • Lifetime Qt Champion

    Drop action: you can for example move an item or copy it e.g. move a file from a folder to another. Thus you won't be doing the same things if you are moving something or if you are copying it.



  • what should i use , if i just want to pass a QString?
    should i use Qt::CopyAction ?


  • Lifetime Qt Champion

    The data contained in the drag object and the action you want to perform based on it are two unrelated things. So it will depend on your application


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.