[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:

#!/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):
		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

if __name__=="__main__":
	app = QApplication(sys.argv)
	myurl = "http://www.google.com"
	widget = htmlViewer(myurl)

More information about the PyQt mailing list