[PyQt] Copying to QClipboard

Jake Richards blaven at gmail.com
Thu Jun 19 20:56:55 BST 2008


Hello:
  I am having a little trouble with the QClipboard in linux.  I seem to be
able to read from the clipboard, but am unable to write to it.  Using the
code below, I get what is currently hilighted and print it out, then try to
set the clipboard, but when I try to paste (using middle mouse button)
nothing is pasted.  We have QT4.3.2 and using an older build of 64 bit
fedora.    Anyone have any tips on how I can do a setText and middle mouse
click in another program the text I set?  Thanks

#!/usr/bin/python
import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QApplication(sys.argv)
myClipBoard = QApplication.clipboard()
test = myClipBoard.text("plain",QClipboard.Selection)
print "The clipboard has " + test
myClipBoard.setText("This is a test of my clipboard",QClipboard.Selection)
myClipBoard.setText("This is a test of my clipboard",QClipboard.Clipboard)
test = myClipBoard.text("plain",QClipboard.Selection)
print "The clipboard has " + test
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080619/a9f2db6d/attachment.html


More information about the PyQt mailing list