def hline(self): """ Insert horizontal line """ # Tag HR is not correctly displayed in QTextview cur_char_fmt = self._text_edit_cursor.charFormat() cur_block_fmt = self._text_edit_cursor.blockFormat() if bool(self._text_edit_cursor.currentTable()): self._text_edit_cursor.insertBlock(cur_block_fmt, cur_char_fmt) block_fmt = QTextBlockFormat() block_fmt.setTopMargin(5) block_fmt.setBottomMargin(5) block_fmt.setAlignment(Qt.AlignLeft) block_fmt.setBackground(QBrush(QColor("#C1C1C1"))) char_format = QTextCharFormat() char_format.setFont(QFont("Arial", 1)) self._text_edit_cursor.insertBlock(block_fmt, char_format) self._text_edit_cursor.insertText(" ") self._text_edit_cursor.insertBlock(cur_block_fmt, cur_char_fmt) self.change(self._text_edit_cursor)
def text_align(self, horiz, vert): fmt = QTextBlockFormat() fmt.setAlignment(horiz) self._text_edit_cursor.mergeBlockFormat(fmt) if self.in_table(): table = self._text_edit_cursor.currentTable() cell = table.cellAt(self._text_edit_cursor) cell_format = cell.format() cell_format.setVerticalAlignment(vert) cell.setFormat(cell_format)
def do_alignment(self, which): with self.editing_cursor() as c: fmt = QTextBlockFormat() fmt.setAlignment(which) c.setBlockFormat(fmt)