Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 22nd, 2011  |  syntax: Python  |  size: 1.03 KB  |  hits: 92  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     def imprime(self):
  2.         printer = QPrinter(QPrinter.HighResolution)
  3.         printer.setPageSize(QPrinter.A4)
  4.         printer.setColorMode(QPrinter.Color)
  5.         printer.setCreator("Dieu")
  6.         printer.setDocName("ma belle image")
  7.         printer.setOutputFileName("image.pdf")
  8.  
  9.         dialog = QPrintDialog(printer, self)
  10.         ret = dialog.exec_()
  11.         if ret != QDialog.Accepted:
  12.             return
  13.  
  14.         painter = QPainter()
  15.         self.export_to_pages(painter, printer)
  16.  
  17.     def export_to_pages(self, painter, printer):
  18.         """ export_to_pages: export the scene on painter with a number of pages
  19.        """
  20.         w = printer.pageRect().width()
  21.         h = printer.pageRect().height()
  22.         numPage = int(round(self.ui.vue.scene.height() / h))
  23.         painter.begin(printer)
  24.         for page in range(0, numPage):
  25.             self.ui.vue.scene.render(painter, QRectF(0, 0, w, h), QRectF(0, h * page, w, h))
  26.             if page < numPage-1:
  27.                printer.newPage()
  28.         painter.end()