Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to custom page size for printing using QPrinter in Pyside6



  • I need to print bill as part of my app. The bill is of dimensions of width 10 inch and heigh 6 inch. I need to print on this type of paper. This app will run on linux. It will be printed using a dotmatrix printer.

    1. how do I set custom page size
    2. I need to set a dpi of 127x60 dpi. How to set resolution SetResolution method takes only one integer.

    When I run the below script it just stuck and nothing happens. It is stuck at Previewer windows Pleast wait.

    @Slot()
        def printPreview(self):
            if not self.m_page:
                return
            if self.m_inPrintPreview:
                return
            self.m_inPrintPreview = True
            printer = QPrinter()
            size=QSize(10,6)
            
            printer.setPageSize(size)
            printer.setResolution(8640)
            printer.setPrinterName("kamtest")
    
            preview = QPrintPreviewDialog(
                printer, QWebEngineView.forPage(self.m_page))
            preview.paintRequested.connect(self.printDocument)
            preview.exec()
            self.m_inPrintPreview = False
    

Log in to reply