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 insertCalendar(self): self.editor.clear() cursor = self.editor.textCursor() cursor.beginEditBlock() date = QDate(self.selectedDate.year(), self.selectedDate.month(), 1) tableFormat = QTextTableFormat() tableFormat.setAlignment(Qt.AlignHCenter) tableFormat.setBackground(QColor("#e0e0e0")) tableFormat.setCellPadding(2) tableFormat.setCellSpacing(4) constraints = [ QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), ] tableFormat.setColumnWidthConstraints(constraints) table = cursor.insertTable(1, 7, tableFormat) frame = cursor.currentFrame() frameFormat = frame.frameFormat() frameFormat.setBorder(1) frame.setFrameFormat(frameFormat) format = cursor.charFormat() format.setFontPointSize(self.fontSize) boldFormat = QTextCharFormat(format) boldFormat.setFontWeight(QFont.Bold) highlightedFormat = QTextCharFormat(boldFormat) highlightedFormat.setBackground(Qt.yellow) for weekDay in range(1, 8): cell = table.cellAt(0, weekDay - 1) cellCursor = cell.firstCursorPosition() cellCursor.insertText(QDate.longDayName(weekDay), boldFormat) table.insertRows(table.rows(), 1) while date.month() == self.selectedDate.month(): weekDay = date.dayOfWeek() cell = table.cellAt(table.rows() - 1, weekDay - 1) cellCursor = cell.firstCursorPosition() if date == QDate.currentDate(): cellCursor.insertText(str(date.day()), highlightedFormat) else: cellCursor.insertText(str(date.day()), format) date = date.addDays(1) if weekDay == 7 and date.month() == self.selectedDate.month(): table.insertRows(table.rows(), 1) cursor.endEditBlock() self.setWindowTitle( "Calendar for %s %d" % (QDate.longMonthName(self.selectedDate.month()), self.selectedDate.year()) )
def insertCalendar(self): self.editor.clear() cursor = self.editor.textCursor() cursor.beginEditBlock() date = QDate(self.selectedDate.year(), self.selectedDate.month(), 1) tableFormat = QTextTableFormat() tableFormat.setAlignment(Qt.AlignHCenter) tableFormat.setBackground(QColor('#e0e0e0')) tableFormat.setCellPadding(2) tableFormat.setCellSpacing(4) constraints = [QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14)] tableFormat.setColumnWidthConstraints(constraints) table = cursor.insertTable(1, 7, tableFormat) frame = cursor.currentFrame() frameFormat = frame.frameFormat() frameFormat.setBorder(1) frame.setFrameFormat(frameFormat) format = cursor.charFormat() format.setFontPointSize(self.fontSize) boldFormat = QTextCharFormat(format) boldFormat.setFontWeight(QFont.Bold) highlightedFormat = QTextCharFormat(boldFormat) highlightedFormat.setBackground(Qt.yellow) for weekDay in range(1, 8): cell = table.cellAt(0, weekDay-1) cellCursor = cell.firstCursorPosition() cellCursor.insertText(QDate.longDayName(weekDay), boldFormat) table.insertRows(table.rows(), 1) while date.month() == self.selectedDate.month(): weekDay = date.dayOfWeek() cell = table.cellAt(table.rows()-1, weekDay-1) cellCursor = cell.firstCursorPosition() if date == QDate.currentDate(): cellCursor.insertText(str(date.day()), highlightedFormat) else: cellCursor.insertText(str(date.day()), format) date = date.addDays(1) if weekDay == 7 and date.month() == self.selectedDate.month(): table.insertRows(table.rows(), 1) cursor.endEditBlock() self.setWindowTitle("Calendar for %s %d" % (QDate.longMonthName(self.selectedDate.month()), self.selectedDate.year()))
def insertCalendar(self): self.editor.clear() cursor = self.editor.textCursor() cursor.beginEditBlock() #self.editor.setStyleSheet("QTextTableFormat {border-color:white}") date = QDate(self.selectedDate.year(), self.selectedDate.month(), 1) tableFormat = QTextTableFormat() self.setStyleSheet( "selection-color: yellow;" "selection-background-color: black;" "border-width: 1px;border-style: solid;border-color: white;") tableFormat.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) tableFormat.setBackground(QColor('#ffffff')) tableFormat.setCellPadding(1) tableFormat.setCellSpacing(0) constraints = [ QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7) ] tableFormat.setColumnWidthConstraints(constraints) table = cursor.insertTable(1, 7, tableFormat) # frame = cursor.currentFrame() # frameFormat = frame.frameFormat() # frameFormat.setBorder(2) # frame.setFrameFormat(frameFormat) format = cursor.charFormat() format.setFontPointSize(self.fontSize) boldFormat = QTextCharFormat(format) boldFormat.setFontWeight(QFont.Bold) dayFormat = QTextCharFormat(format) #self.editor.setStyleSheet("color:red;") dayFormat.setForeground(QColor('#f44336')) highlightedFormat = QTextCharFormat(boldFormat) highlightedFormat.setBackground(Qt.yellow) highlightedFormat.setFontUnderline(True) highlightedFormat.setUnderlineColor(QColor('#f44336')) # highlightedFormat.setColor(Qt.white) for weekDay in range(1, 8): cell = table.cellAt(0, weekDay - 1) cellCursor = cell.firstCursorPosition() cellCursor.insertText(day[weekDay - 1], dayFormat) table.insertRows(table.rows(), 1) while date.month() == self.selectedDate.month(): weekDay = date.dayOfWeek() cell = table.cellAt(table.rows() - 1, weekDay - 1) cellCursor = cell.firstCursorPosition() if date == QDate.currentDate(): cellCursor.insertText(str(date.day()), highlightedFormat) else: cellCursor.insertText(str(date.day()), format) date = date.addDays(1) if weekDay == 7 and date.month() == self.selectedDate.month(): table.insertRows(table.rows(), 1) cursor.endEditBlock() self.setWindowTitle("Calendar for %s %d" % (QDate.longMonthName( self.selectedDate.month()), self.selectedDate.year()))