def handlePaintRequest(self, printer): document = QTextDocument() document.setPageSize(QSizeF(printer.pageRect().size())) cursor = QTextCursor(document) tableFormat = QTextTableFormat() TableText = QTextCharFormat() TableText.setLayoutDirection(Qt.RightToLeft) # tableFormat.setAlignment(Qt.AlignCenter) tableFormat.setBackground(QColor('#d3fbf5')) tableFormat.setCellPadding(3) tableFormat.setCellSpacing(4) tableFormat.setLayoutDirection(Qt.RightToLeft) tableFormat.setBorderStyle(QTextTableFormat.BorderStyle_Double) TitrFormat = QTextCharFormat() fontTitr = QFont() fontTitr.setBold(True) TitrFormat.setFont(fontTitr) SotonFormat = QTextCharFormat() TitrFormat.setLayoutDirection(Qt.RightToLeft) # SotonFormat.setBackground(QColor('#EEF9C9')) SotonFormat.setFont(fontTitr) cursor.insertText(self.TableTitr + "\n", TitrFormat) model = self.ui.tableView_result.model() table = cursor.insertTable(model.rowCount() + 1, model.columnCount(), tableFormat) headers = [ 'پلاک', 'بخش', 'تعداد جلد', 'تعداد صفحات', 'نوع', 'همکار تقاضاکننده', 'تحویل گیرنده', 'علت درخواست', 'توضیحات', 'تاریخ تحویل', 'ساعت تحویل', 'تاریخ بازگشت', 'ساعت بازگشت' ] self.tableResult.insertRows(10, 10) for header in reversed(headers): cursor.insertText(header, SotonFormat) cursor.movePosition(QTextCursor.NextCell) for row in range(table.rows()): for column in reversed(range(table.columns())): cursor.insertText( self.tableResult.data(self.tableResult.index(row, column)), TableText) cursor.movePosition(QTextCursor.NextCell) cursor.movePosition(QTextCursor.NextBlock) cursor.insertText('- سامانه بایگانی ثبت ماسال -', TitrFormat) # printer.setFullPage(True) document.print_(printer)
def insert_table(self): self.param = mainDialog() table_format = QTextTableFormat() table_format.setWidth(QTextLength(QTextLength.PercentageLength,50)) table_format.setAlignment(Qt.AlignCenter) table_format.setCellPadding(5) table_format.setCellSpacing(0) ret = self.param.exec_() if ret == 1: if self.param.border_style == 'Dotted': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_Dotted) elif self.param.border_style == 'Groove': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_Groove) elif self.param.border_style == 'Dashed': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_Dashed) elif self.param.border_style == 'DotDotDash': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_DotDotDash) elif self.param.border_style == 'DotDash': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_DotDash) elif self.param.border_style == 'Double': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_Double) elif self.param.border_style == 'Inset': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_Inset) elif self.param.border_style == 'None': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_Inset) elif self.param.border_style == 'Outset': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_Outset) elif self.param.border_style == 'Ridge': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_Ridge) elif self.param.border_style == 'Solid': table_format.setBorderStyle(QTextFrameFormat.BorderStyle_Solid) if self.param.layout_Direction == 'Left To Right': table_format.setLayoutDirection(Qt.LeftToRight) elif self.param.layout_Direction == 'Right To Left': table_format.setLayoutDirection(Qt.RightToLeft) cursor = self.ui.textEdit.textCursor() cursor.insertTable(self.param.number_of_rows,self.param.number_of_columns,table_format) self.param.close()