Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPrintPreviewDialog - good preview but incorrect printing on Windows 7
Forum Updated to NodeBB v4.3 + New Features

QPrintPreviewDialog - good preview but incorrect printing on Windows 7

Scheduled Pinned Locked Moved General and Desktop
pyqt5python
3 Posts 1 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thierebassi
    wrote on last edited by thierebassi
    #1

    Hi All,
    I am having a printing problem with PyQt-5.4.1 for Python 3.4.1/Windows 7.
    I want to print an HTML document and the following is my testing code (QWebview and QPrintPreviewDialog):

    import sys, os
    from PyQt5.QtCore import *
    from PyQt5.QtWidgets import *
    from PyQt5 import QtWebKitWidgets
    from PyQt5.QtPrintSupport import QPrintPreviewDialog, QPrinter
    
    class appFormPrintWebviev(QtWebKitWidgets.QWebView):
       def __init__(self, parent=None, ):
              super(appFormPrintWebviev,self).__init__(parent)
             self.loadFinished.connect(self.printPreview)
             self.drawActeNaissance()
    
        def printPreview(self):
    
            dialog = QPrintPreviewDialog(self.printer)
            dialog.setWindowState(Qt.WindowMaximized)
            dialog.paintRequested.connect(self.print_)
            dialog.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint | Qt.WindowContextHelpButtonHint)
            dialog.exec()
    
        def drawActeNaissance(self):
            import codecs
            html = codecs.open(b"template.html",encoding='utf-8').read()
            baseurl = QUrl.fromLocalFile(os.path.join(os.getcwd(),"index.html"))
            self.setHtml(html, baseurl)
            self.printer = QPrinter();
            self.printer.setPageSize(QPrinter.A4);
            self.printer.setOrientation(QPrinter.Portrait);
            self.printer.setPageMargins(10,10,10,10,QPrinter.Millimeter);
            self.setFixedWidth(1000)
    
    if __name__ == '__main__':
            app = QApplication(sys.argv)
            form = appFormPrintWebviev()
            form.show()
            sys.exit(app.exec_())
    

    My problem is that the QPrintPreviewDialog correctly displays the document in previewing window (see: http://s1.postimg.org/fc4ctwian/Print_Preview.png), but the document is not correctly printed. The printer, PDFCreator, prints a disorganized document (see: http://s15.postimg.org/kj940hb23/final_printed_doc.png)

    I don't know why, but the same code with adaptations works perfectly in PyQt-4.10.4 and Python 2.7.

    Thieré
    Regards

    PS : I have already posted this message to PyQT list but I havd no answer.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thierebassi
      wrote on last edited by
      #2

      After a looking around Qt BugTracker
      it seams that it is a known problem from QT 5.0.1 which has desapeared in version 5.3 and reappeared in 5.4.
      https://bugreports.qt.io/browse/QTBUG-36308
      But it is not solved yet I think for official version of Qt 5.4.1 https://bugreports.qt.io/browse/QTBUG-43145
      Even if patch seems to be available https://codereview.qt-project.org/#/c/111658/

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thierebassi
        wrote on last edited by
        #3

        I solved I by moving from PyQT5.4.1 to PyQT5.3.2.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved