コード例 #1
0
    def build_invoice(self, data):
        document = QTextDocument()
        self.setDocument(document)
        document.setPageSize(QSizeF(self.doc_width, self.doc_height))
        document.setDefaultFont(font)
        cursor = QTextCursor(document)
        cursor.insertText(f"Customer Name: {data['c_name']}\n")
        cursor.insertText(f"Customer Address: {data['c_addr']}\n")
        cursor.insertText(f"Date: {data['i_date']}\n")
        cursor.insertText(f"Total Due: {data['total_due']}\n")
# +        
        return document                                                         # +++
コード例 #2
0
ファイル: main_window.py プロジェクト: konserw/pyOffer
    def print(self, printer: QPrinter) -> None:
        print_options = PrintOptions(
            print_no=self.ui.check_box_no_column.isChecked(),
            print_code=self.ui.check_box_code_column.isChecked(),
            print_description=self.ui.check_box_details_column.isChecked(),
            print_list_price=self.ui.check_box_list_price_column.isChecked(),
            print_discount=self.ui.check_box_discount_column.isChecked(),
            print_price=self.ui.check_box_price_column.isChecked(),
            print_quantity=self.ui.check_box_quantity_column.isChecked(),
            print_total=self.ui.check_box_total_column.isChecked()
        )
        margin = 5
        printer.setPageSize(QPrinter.A4)
        printer.setPageMargins(margin, margin, margin, margin, QPrinter.Millimeter)
        printer.setResolution(96)

        doc = QTextDocument()
        doc.setUseDesignMetrics(True)
        doc.setDefaultFont(self.offer_font)
        doc.setHtml(self.offer.printout(print_options))
        doc.setPageSize(printer.pageRect().size())
        doc.print_(printer)