[PyQt] Re: Code example for QPrinter (PyQt4)
Eduardo Willians
edujurista at gmail.com
Mon Jan 19 16:20:17 GMT 2009
2009/1/19 Eduardo Willians <edujurista at gmail.com>:
> I searched a lot on google and stuff, but I wasn't able to find a code
> example for printing with PyQt4.
>
> If know a tutorial or have a simple file.py that shows how to print
> (through a printer) with PyQt4 please send me.
>
> Thanks.
>
> Eduardo Willians
Really sorry, I just found. I post it:
<code>
#!/usr/bin/env python
"""
Lets get the print thing working
"""
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import PyQt4.QtWebKit as QtWebKit
import sys
class htmlViewer(QtWebKit.QWebView):
def __init__(self,url, parent=None):
QtWebKit.QWebView.__init__(self,parent)
self.setUrl(QUrl(url))
self.preview = QPrintPreviewDialog()
self.connect(self.preview,SIGNAL("paintRequested (QPrinter
*)"),SLOT("print (QPrinter *)"))
self.connect(self,SIGNAL("loadFinished (bool)"),self.execpreview)
def execpreview(self,arg):
print arg
self.preview.exec_()
if __name__=="__main__":
app = QApplication(sys.argv)
myurl = "http://www.google.com"
widget = htmlViewer(myurl)
widget.show()
sys.exit(app.exec_())
</code>
More information about the PyQt
mailing list