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.
Probably you didn't set mime type needed for
QClipboard
. For example, in GNOME this isx-special/gnome-copied-files
. When usingQMimeData
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
isx-special/gnome-copied-files
, or else which can be recognized by file manager.