[PyQt] printpreview.cpp to printpreview.py

Mark Summerfield mark at qtrac.eu
Thu Nov 15 09:06:34 GMT 2007

On 2007-11-15, alban.minassian at free.fr wrote:
> Hello
> I can not convert a few lines of code file C: \ Qt \ 4.3.2 \ demos \
> PYQT :
> self.paperSize.rwidth() *= QtCore.qreal(self.view.logicalDpiX()) /
> self.printer.logicalDpiX();
> SyntaxError: illegal expression for augmented assignment
> How to convert these two lines in pyqt?
>    paperSize.rwidth() *= qreal(view->logicalDpiX()) /
> printer.logicalDpiX();
>    paperSize.rheight() *= qreal(view->logicalDpiY()) /
> printer.logicalDpiY();

You are trying to update a QSizeF object and according to the PyQt docs
the relevant augmented assignments take a Python float not a

But I tried converting to floats and got the same problem you did.

The answer I think is to avoid assignments to C++ reference return
values (esp. since the rwidth() and rheight() methods don't appear in
the docs which may be a hint that they don't work:-)

So maybe write something like this instead (untested):

self.paperSize.setWidth(self.paperSize.width() * \
	(view.logicalDpiX() / float(printer.logicalDpiX)))
self.paperSize.setHeight(self.paperSize.height() * \
	(view.logicalDpiY() / float(printer.logicalDpiY)))

Mark Summerfield, Qtrac Ltd., www.qtrac.eu

More information about the PyQt mailing list