Skip to content

PythonQt.Qt.QTextDocument

QTextDocument

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QTextDocument is a container for structured rich text documents, providing support for styled text and various types of document elements, such as lists, tables, frames, and images. They can be created for use in a QTextEdit, or used independently.

Each document element is described by an associated format object. Each format object is treated as a unique object by QTextDocuments, and can be passed to objectForFormat() to obtain the document element that it is applied to.

A QTextDocument can be edited programmatically using a QTextCursor, and its contents can be examined by traversing the document structure. The entire document structure is stored as a hierarchy of document elements beneath the root frame, found with the rootFrame() function. Alternatively, if you just want to iterate over the textual contents of the document you can use begin(), end(), and findBlock() to retrieve text blocks that you can examine and iterate over.

The layout of a document is determined by the documentLayout(); you can create your own QAbstractTextDocumentLayout subclass and set it using setDocumentLayout() if you want to use your own layout logic. The document's title and other meta-information can be obtained by calling the metaInformation() function. For documents that are exposed to users through the QTextEdit class, the document title is also available via the QTextEdit::documentTitle() function.

The toPlainText() and toHtml() convenience functions allow you to retrieve the contents of the document as plain text and HTML. The document's text can be searched using the find() functions.

Undo/redo of operations performed on the document can be controlled using the setUndoRedoEnabled() function. The undo/redo system can be controlled by an editor widget through the undo() and redo() slots; the document also provides contentsChanged(), undoAvailable(), and redoAvailable() signals that inform connected editor widgets about the state of the undo/redo system. The following are the undo/redo operations of a QTextDocument:

  • Insertion or removal of characters. A sequence of insertions or removals within the same text block are regarded as a single undo/redo operation.
  • Insertion or removal of text blocks. Sequences of insertion or removals in a single operation (e.g., by selecting and then deleting text) are regarded as a single undo/redo operation.
  • Text character format changes.
  • Text block format changes.
  • Text block group format changes.

Source: https://doc.qt.io/archives/qt-5.15/qtextdocument.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
DocumentTitle attribute Any (shared captured text)
DocumentUrl attribute Any (shared captured text)
FindBackward attribute Any (shared captured text)
FindCaseSensitively attribute Any (shared captured text)
FindFlag attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
FindFlags attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
FindWholeWords attribute Any (shared captured text)
HtmlResource attribute Any (shared captured text)
ImageResource attribute Any (shared captured text)
MarkdownFeatures attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
MarkdownResource attribute Any (shared captured text)
MetaInformation attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
RedoStack attribute Any (shared captured text)
ResourceType attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
Stacks attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
StyleSheetResource attribute Any (shared captured text)
UndoAndRedoStacks attribute Any (shared captured text)
UndoStack attribute Any (shared captured text)
UnknownResource attribute Any (shared captured text)
UserResource attribute Any (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
addResource function (self, type: int, name: Any, resource: Any) -> None X.addResource(type, name, resource) (shared captured text)
adjustSize function (self) -> None Adjusts the document to a reasonable size. (shared captured text)
allFormats function (self) -> tuple X.allFormats() -> tuple (shared captured text)
appendUndoItem function (self, a: Any) -> Any (shared captured text)
availableRedoSteps function (self) -> int X.availableRedoSteps() -> int (shared captured text)
availableUndoSteps function (self) -> int X.availableUndoSteps() -> int (shared captured text)
baseUrl attribute QUrl This property holds the base URL used to resolve relative resource URLs within the document. (shared captured text)
baseUrlChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.baseUrlChanged; argument details are not documented.
begin function (self) -> Any X.begin() -> PythonQt.QtGui.QTextBlock (shared captured text)
blockCount attribute int Returns the number of text blocks in the document. (shared captured text)
blockCountChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.blockCountChanged; argument details are not documented.
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
characterAt function (self, pos: int) -> str Returns the character at position pos, or a null character if the position is out of range. (shared captured text)
characterCount function (self) -> int X.characterCount() -> int (shared captured text)
childEvent function (self, event: Any) -> Any (shared captured text)
children function (self) -> tuple X.children() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
clear function (self) -> None Clears the document. (shared captured text)
clearUndoRedoStacks function (self, historyToClear: Any) -> None Clears the stacks specified by stacksToClear. (shared captured text)
clone function (self, parent: Any) -> Any X.clone(parent) -> PythonQt.QtGui.QTextDocument (shared captured text)
connect function (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool X.connect(signal, receiver, slot, type) -> bool (shared captured text)
contentsChange function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.contentsChange; argument details are not documented.
contentsChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.contentsChanged; argument details are not documented.
createObject function (self, f: Any) -> Any X.createObject(f) -> PythonQt.QtGui.QTextObject (shared captured text)
cursorPositionChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.cursorPositionChanged; argument details are not documented.
customEvent function (self, event: Any) -> Any (shared captured text)
defaultCursorMoveStyle function (self) -> Any The default cursor movement style is used by all [QTextCursor](https://doc.qt.io/archives/qt-5.15/qtextcursor.html) objects created from the document. (shared captured text)
defaultFont attribute QFont This property holds the default font used to display the document's text (shared captured text)
defaultStyleSheet attribute str The default style sheet is applied to all newly HTML formatted text that is inserted into the document, for example using [setHtml](https://doc.qt.io/archives/qt-5.15/qtextdocument.html#setHtml)()… (shared captured text)
defaultTextOption function (self) -> Any X.defaultTextOption() -> PythonQt.QtGui.QTextOption (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
deleteLater function (self) -> Any (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.destroyed; argument details are not documented.
disconnect function (self, signal: Any, receiver: Any, slot: Any) -> bool X.disconnect(signal, receiver, slot) -> bool (shared captured text)
documentLayout function (self) -> Any X.documentLayout() -> PythonQt.QtGui.QAbstractTextDocumentLayout (shared captured text)
documentLayoutChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.documentLayoutChanged; argument details are not documented.
documentMargin attribute float The margin around the document. (shared captured text)
drawContents function (self, painter: Any, rect: Any) -> None X.drawContents(painter, rect) (shared captured text)
dumpObjectInfo function (self) -> Any (shared captured text)
dumpObjectTree function (self) -> Any (shared captured text)
dynamicPropertyNames function (self) -> Any (shared captured text)
end function (self) -> Any X.end() -> PythonQt.QtGui.QTextBlock (shared captured text)
event function (self, event: Any) -> bool X.event(event) -> bool (shared captured text)
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
find function (self, expr: Any, cursor: Any, options: Any) -> Any X.find(expr, cursor, options) -> PythonQt.QtGui.QTextCursor (shared captured text)
findBlock function (self, pos: int) -> Any X.findBlock(pos) -> PythonQt.QtGui.QTextBlock (shared captured text)
findBlockByLineNumber function (self, blockNumber: int) -> Any X.findBlockByLineNumber(blockNumber) -> PythonQt.QtGui.QTextBlock (shared captured text)
findBlockByNumber function (self, blockNumber: int) -> Any X.findBlockByNumber(blockNumber) -> PythonQt.QtGui.QTextBlock (shared captured text)
findChild function (self, type: Any, name: Any) -> Any X.findChild(type, name) -> PythonQt.private.QObject (shared captured text)
findChildren function (self, type: Any, name: Any) -> tuple X.findChildren(type, name) -> tuple (shared captured text)
firstBlock function (self) -> Any X.firstBlock() -> PythonQt.QtGui.QTextBlock (shared captured text)
frameAt function (self, pos: int) -> Any X.frameAt(pos) -> PythonQt.QtGui.QTextFrame (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
idealWidth function (self) -> float X.idealWidth() -> float (shared captured text)
indentWidth attribute float Returns the width used for text list and text block indenting. (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
isEmpty function (self) -> bool X.isEmpty() -> bool (shared captured text)
isModified function (self) -> bool X.isModified() -> bool (shared captured text)
isRedoAvailable function (self) -> bool X.isRedoAvailable() -> bool (shared captured text)
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isUndoAvailable function (self) -> bool X.isUndoAvailable() -> bool (shared captured text)
isUndoRedoEnabled function (self) -> bool X.isUndoRedoEnabled() -> bool (shared captured text)
isWidgetType function (self) -> bool X.isWidgetType() -> bool (shared captured text)
isWindowType function (self) -> bool X.isWindowType() -> bool (shared captured text)
killTimer function (self, id: Any) -> Any (shared captured text)
lastBlock function (self) -> Any X.lastBlock() -> PythonQt.QtGui.QTextBlock (shared captured text)
lineCount function (self) -> int X.lineCount() -> int (shared captured text)
loadResource function (self, type: int, name: Any) -> Any X.loadResource(type, name) -> object (shared captured text)
markContentsDirty function (self, *args: Any, **kwargs: Any) -> None X.markContentsDirty(from, length) (shared captured text)
maximumBlockCount attribute int Specifies the limit for blocks in the document. (shared captured text)
metaInformation function (self, info: Any) -> str X.metaInformation(info) -> str (shared captured text)
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
modificationChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.modificationChanged; argument details are not documented.
modified attribute Any This property holds whether the document has been modified by the user (shared captured text)
moveToThread function (self, thread: Any) -> Any (shared captured text)
object function (self, objectIndex: int) -> Any X.object(objectIndex) -> PythonQt.QtGui.QTextObject (shared captured text)
objectForFormat function (self, arg__1: Any) -> Any X.objectForFormat(arg__1) -> PythonQt.QtGui.QTextObject (shared captured text)
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.objectNameChanged; argument details are not documented.
pageCount function (self) -> int X.pageCount() -> int (shared captured text)
pageSize attribute QSizeF This property holds the page size that should be used for laying out the document (shared captured text)
parent function (self) -> Any X.parent() -> PythonQt.private.QObject (shared captured text)
print function (self, printer: Any) -> Any Prints the document to the given printer. (shared captured text)
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
redo function (self, cursor: Any) -> None This is an overloaded function. (shared captured text)
redoAvailable function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.redoAvailable; argument details are not documented.
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
resource function (self, type: int, name: Any) -> Any X.resource(type, name) -> object (shared captured text)
revision function (self) -> int X.revision() -> int (shared captured text)
rootFrame function (self) -> Any X.rootFrame() -> PythonQt.QtGui.QTextFrame (shared captured text)
sender function (self) -> Any X.sender() -> PythonQt.private.QObject (shared captured text)
senderSignalIndex function (self) -> int X.senderSignalIndex() -> int (shared captured text)
setBaseUrl function (self, url: Any) -> None (shared captured text)
setDefaultCursorMoveStyle function (self, style: Any) -> None Sets the default cursor movement style to the given style. (shared captured text)
setDefaultFont function (self, font: Any) -> None Sets the default font to use in the document layout. (shared captured text)
setDefaultStyleSheet function (self, sheet: str) -> None (shared captured text)
setDefaultTextOption function (self, option: Any) -> None Sets the default text option to option. (shared captured text)
setDocumentLayout function (self, layout: Any) -> None Sets the document to use the given layout. (shared captured text)
setDocumentMargin function (self, margin: float) -> None (shared captured text)
setHtml function (self, html: str) -> None Replaces the entire contents of the document with the given HTML-formatted text in the html string. (shared captured text)
setIndentWidth function (self, width: float) -> None Sets the width used for text list and text block indenting. (shared captured text)
setMaximumBlockCount function (self, maximum: int) -> None (shared captured text)
setMetaInformation function (self, info: Any, arg__2: str) -> None X.setMetaInformation(info, arg__2) (shared captured text)
setModified function (self, m: bool) -> None (shared captured text)
setObjectName function (self, name: Any) -> Any (shared captured text)
setPageSize function (self, size: Any) -> None (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setPlainText function (self, text: str) -> None Replaces the entire contents of the document with the given plain text. (shared captured text)
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setTextWidth function (self, width: float) -> None (shared captured text)
setUndoRedoEnabled function (self, enable: bool) -> None (shared captured text)
setUseDesignMetrics function (self, b: bool) -> None (shared captured text)
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
size attribute QSizeF Returns the actual size of the document. (shared captured text)
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
textWidth attribute float The text width specifies the preferred width for text in the document. (shared captured text)
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
toHtml function (self, encoding: Any) -> str X.toHtml(encoding) -> str (shared captured text)
toPlainText function (self) -> str X.toPlainText() -> str (shared captured text)
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)
undo function (self, cursor: Any) -> None This is an overloaded function. (shared captured text)
undoAvailable function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.undoAvailable; argument details are not documented.
undoCommandAdded function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QTextDocument.undoCommandAdded; argument details are not documented.
undoRedoEnabled attribute Any This property holds whether undo/redo are enabled for this document (shared captured text)
useDesignMetrics attribute bool This property holds whether the document uses design metrics of fonts to improve the accuracy of text layout (shared captured text)