Qt Pyside2 访问剪贴板

目录

Qt/Pyside2 读取系统剪贴板内容

import sys
from PySide2.QtWidgets import QApplication

app = QApplication(sys.argv)
clipboard = app.clipboard()

print(clipboard.mimeData().formats())
print(clipboard.mimeData().data(clipboard.mimeData().formats()[0]))

app.closeAllWindows()
app=None

mimeData() 就和 drag 时对 mimeData() 的操作一样了。

引用自 doc.qt.io:

QClipboard supports the same data types that QDrag does, and uses similar mechanisms. For advanced clipboard usage read Drag and Drop .