3

c++/Qt how to handle clipboard to copy files

Hi,

I'm currently developing an app in C++/Qt . I have made some modifications in the Drag and Drop to be able to copy a file from the local machine (Mac OSX) to an Android Device (using the MTP access). The Mtp part is already done. now, I'm not able to copy a file from the android device to local machine using the Drag and Drop move.

Below is the init of the class TreeWidget which contain items

TreeView::TreeView(mtp_wrapper& device, MainWindow& parent) :
    m_device(device), w_parent(parent)
{

    //new FileMimeType();

    setSortingEnabled(true);
    setColumnWidth(0, 400);
    setExpandsOnDoubleClick(true);

    setDragDropMode(DragDrop);
    setDragEnabled(true);
    setDropIndicatorShown(true);
    setMouseTracking(true);
    setAcceptDrops(true);
    setAutoFillBackground(true);

the header of the class is defined

class TreeView : public QTreeWidget
{
    Q_OBJECT
public:
    TreeView(mtp_wrapper& device, MainWindow& parent);

I have also reuse all the private slots below

void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void dragMoveEvent(QDragMoveEvent * event);
void dragLeaveEvent(QDragLeaveEvent* event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);

What is strange is that by default when moving a file from my app to the local machine (desktop or finder), a file is created with the filename of my file. By default Qt create a filename.textClipping file.

What I need is to block this creation of the Clipping file and replace it by my own copy function from the android dev to the machine.

My other concerns is that when my mouse is on the desktop or somewhere in the finder, I don't see which type of event/mimeData can be use to catch the destination

Any idea on what class need to be addressed

Thanks

Seb
  • 2,929
  • 4
  • 30
  • 73
  • 1
    You should check drag-n-drop methods of your model and implement them according to your logic. Usage of `QTreeWidget` is bad practice in your case. Try to use `QTreeView` + `QStandardItemModel` (you need to override necessary methods) – Dmitry Sazonov Feb 20 '15 at 10:25
  • Thank SaZ. The app is 90% ended and I just need to manage the drag/drop from device to mac and mac to device work. Can I consider that it will work but it's cleaner to do it based on QtreeView – Seb Feb 20 '15 at 20:15

0 Answers0