Are you accounting for the higher DPI of printers (300, 600) vs that of the 
screen (72 or 90)? You'll need to scale accordingly.



----- Original Message ----
From: Robert J. Hansen <[email protected]>
To: [email protected]
Sent: Thursday, July 30, 2009 1:58:59 PM
Subject: [PyQt] Printing a widget

For a piece of code I'm working on, I need the ability to render a QWidget to 
the printer directly.  The logic goes something like this:

def printout(self):
    widget = self.tab_widget.currentWidget()
    if widget == None:
        # The 'print' button should've been disabled;
        # do so now.
        self.update_ui()
        return
    try:
        widget.printout()
    except:
        painter = QPainter(self.get_printer())
        rectangle = painter.viewport()
        size = widget.size()
        size.scale(rectangle.size(), Qt.KeepAspectRatio)
        painter.setViewport(rectangle.x(), rectangle.y(),
            size.width(), size.height())
        widget.render(painter)

... Unfortunately, this code does not seem to work.  Something gets printed, 
but it's such a tiny postage stamp that it's not usable for my purposes.  For 
my tests the widget has been a QLabel; the 'except' block is executed.

What I'm looking for is some way to print such that the widget's width spans 
the width of the page, and its length will be split up among multiple pages if 
necessary.  If anyone can give me the magic invocation that will do this, or 
can direct me to the proper part of the PyQt documentation that tells how to do 
this, I would be deeply appreciative.  Thank you!



_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt



      
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to