[PyQt] printpreview.cpp to printpreview.py

alban.minassian at free.fr alban.minassian at free.fr
Thu Nov 15 08:30:16 GMT 2007


Hello

I can not convert a few lines of code file C: \ Qt \ 4.3.2 \ demos \
textedit \ printpreview.cpp.
void PrintPreview::setup()
{
   QSizeF page = printer.pageRect().size();
   paperSize = printer.paperRect().size();
   paperSize.rwidth() *= qreal(view->logicalDpiX()) /
printer.logicalDpiX();
   paperSize.rheight() *= qreal(view->logicalDpiY()) /
printer.logicalDpiY();

   pageTopLeft = printer.pageRect().topLeft();
   pageTopLeft.rx() *= qreal(view->logicalDpiX()) / printer.logicalDpiX();
   pageTopLeft.ry() *= qreal(view->logicalDpiY()) / printer.logicalDpiY();

   page.setWidth(page.width() * view->logicalDpiX() /
printer.logicalDpiX());
   page.setHeight(page.height() * view->logicalDpiY() /
printer.logicalDpiY());

   // add a nice 2 cm margin
   const qreal margin = inchesToPixels(mmToInches(20), this);
   QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
   fmt.setMargin(margin);
   doc->rootFrame()->setFrameFormat(fmt);

   doc->setPageSize(page);
}

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();


Thanks for your help
Ami







More information about the PyQt mailing list