how to copy or cut a file for nautilus using qclipboard

369 views Asked by At

I want to copy a file to nautilus using Qclipboard. This is what I made

from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
data = QtCore.QMimeData()
url = QtCore.QUrl.fromLocalFile('/home/newtron/test/main.qml')
data.setUrls([url])

QApplication.clipboard().setMimeData(data)

But the URL copied as a link not as a file. What do I need to do to set clipboard data as a file.

using gnome and linux.

1

There are 1 answers

2
user3417815 On BEST ANSWER

Probably you didn't set mime type needed for QClipboard. For example, in GNOME this is x-special/gnome-copied-files. When using QMimeData check out this page https://doc.qt.io/qt-5/qmimedata.html#setData for C++, or this for Python https://doc.qt.io/qtforpython/PySide2/QtCore/QMimeData.html#PySide2.QtCore.PySide2.QtCore.QMimeData.setData .

So you need to include it in your code:

PySide2.QtCore.QMimeData.setData(mimetype, data)

Where mimetype is x-special/gnome-copied-files, or else which can be recognized by file manager.