def pasteFile(self, url): new = read_file_content(url.toLocalFile()) if new: # inserting text like this allows undo cursor = QTextCursor(self.document()) cursor.select(QTextCursor.Document) cursor.insertText(new)
def drawContents(self, painter): """ Reimplementation of drawContents to limit the drawing inside `textRext`. """ painter.setPen(self.__color) painter.setFont(self.font()) if self.__textRect: rect = self.__textRect else: rect = self.rect().adjusted(5, 5, -5, -5) tformat = self.__textFormat if tformat == Qt.AutoText: if mightBeRichText(self.__message): tformat = Qt.RichText else: tformat = Qt.PlainText if tformat == Qt.RichText: doc = QTextDocument() doc.setHtml(self.__message) doc.setTextWidth(rect.width()) cursor = QTextCursor(doc) cursor.select(QTextCursor.Document) fmt = QTextBlockFormat() fmt.setAlignment(self.__alignment) cursor.mergeBlockFormat(fmt) painter.save() painter.translate(rect.topLeft()) doc.drawContents(painter) painter.restore() else: painter.drawText(rect, self.__alignment, self.__message)