[PySide] Working with the clipboard cross-plattafrom

Zahari Dim zaharid at gmail.com
Tue Oct 15 00:45:28 CEST 2013


Hi,

I need to programatically fill the clipboard with content that has custom
mime types. I could make it work with PyQt4 (with some cabarets). But when
I try the same for PySide, the application I try to paste to just freezes,
both under windows and linux. How could  make this work with PySide:


 #This works
from PyQt4 import QtCore, QtGui
#This doesn't
#from PySide import QtCore, QtGui

def start_app():
    app = QtCore.QCoreApplication.instance()
    if app is None:
        print "app"
        app = QtGui.QApplication([])
    return app


#@run_in_qt
def set_clipboard(content, mime = 'text/plain'):

    mymime = QtCore.QMimeData()
    mymime.setData(mime, QtCore.QByteArray(content.encode('utf-8')))
    app = start_app()
    clipboard = app.clipboard()
    clipboard.setMimeData(mymime)


def get_clipboard():
    content = QtGui.QApplication.clipboard().mimeData()
    avaiable_formats = content.formats()
    return {fmt:content.data(fmt) for fmt in avaiable_formats}


#PyQt4 doesn't work without this line _outside_ any of the functions....
__app = start_app()


Any help would be appreciated.

Zahari Dimitrov.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20131015/d2da85a9/attachment.html>


More information about the PySide mailing list