Skip to content

PythonQt.QtGui.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
DocumentUrl attribute Any
FindBackward attribute Any
FindCaseSensitively attribute Any
FindFlag attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
FindFlags attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
FindWholeWords attribute Any
HtmlResource attribute Any
ImageResource attribute Any
MarkdownFeatures attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
MarkdownResource attribute Any
MetaInformation attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
RedoStack attribute Any
ResourceType attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
Stacks attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
StyleSheetResource attribute Any
UndoAndRedoStacks attribute Any
UndoStack attribute Any
UnknownResource attribute Any
UserResource attribute Any
__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)
adjustSize function (self) -> None Adjusts the document to a reasonable size.
allFormats function (self) -> tuple X.allFormats() -> tuple
appendUndoItem function (self, a: Any) -> Any
availableRedoSteps function (self) -> int X.availableRedoSteps() -> int
availableUndoSteps function (self) -> int X.availableUndoSteps() -> int
baseUrl attribute QUrl This property holds the base URL used to resolve relative resource URLs within the document.
baseUrlChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QTextDocument.baseUrlChanged; argument details are not documented.
begin function (self) -> Any X.begin() -> PythonQt.QtGui.QTextBlock
blockCount attribute int Returns the number of text blocks in the document.
blockCountChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.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.
characterCount function (self) -> int X.characterCount() -> int
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.
clearUndoRedoStacks function (self, historyToClear: Any) -> None Clears the stacks specified by stacksToClear.
clone function (self, parent: Any) -> Any X.clone(parent) -> PythonQt.QtGui.QTextDocument
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.QtGui.QTextDocument.contentsChange; argument details are not documented.
contentsChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QTextDocument.contentsChanged; argument details are not documented.
createObject function (self, f: Any) -> Any X.createObject(f) -> PythonQt.QtGui.QTextObject
cursorPositionChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.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.
defaultFont attribute QFont This property holds the default font used to display the document's 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)()…
defaultTextOption function (self) -> Any X.defaultTextOption() -> PythonQt.QtGui.QTextOption
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.QtGui.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
documentLayoutChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QTextDocument.documentLayoutChanged; argument details are not documented.
documentMargin attribute float The margin around the document.
drawContents function (self, painter: Any, rect: Any) -> None X.drawContents(painter, rect)
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
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
findBlock function (self, pos: int) -> Any X.findBlock(pos) -> PythonQt.QtGui.QTextBlock
findBlockByLineNumber function (self, blockNumber: int) -> Any X.findBlockByLineNumber(blockNumber) -> PythonQt.QtGui.QTextBlock
findBlockByNumber function (self, blockNumber: int) -> Any X.findBlockByNumber(blockNumber) -> PythonQt.QtGui.QTextBlock
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
frameAt function (self, pos: int) -> Any X.frameAt(pos) -> PythonQt.QtGui.QTextFrame
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
indentWidth attribute float Returns the width used for text list and text block indenting.
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
isModified function (self) -> bool X.isModified() -> bool
isRedoAvailable function (self) -> bool X.isRedoAvailable() -> bool
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isUndoAvailable function (self) -> bool X.isUndoAvailable() -> bool
isUndoRedoEnabled function (self) -> bool X.isUndoRedoEnabled() -> bool
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
lineCount function (self) -> int X.lineCount() -> int
loadResource function (self, type: int, name: Any) -> Any X.loadResource(type, name) -> object
markContentsDirty function (self, *args: Any, **kwargs: Any) -> None X.markContentsDirty(from, length)
maximumBlockCount attribute int Specifies the limit for blocks in the document.
metaInformation function (self, info: Any) -> str X.metaInformation(info) -> str
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
modificationChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QTextDocument.modificationChanged; argument details are not documented.
modified attribute Any This property holds whether the document has been modified by the user
moveToThread function (self, thread: Any) -> Any (shared captured text)
object function (self, objectIndex: int) -> Any X.object(objectIndex) -> PythonQt.QtGui.QTextObject
objectForFormat function (self, arg__1: Any) -> Any X.objectForFormat(arg__1) -> PythonQt.QtGui.QTextObject
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QTextDocument.objectNameChanged; argument details are not documented.
pageCount function (self) -> int X.pageCount() -> int
pageSize attribute QSizeF This property holds the page size that should be used for laying out the document
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.
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
redo function (self, cursor: Any) -> None This is an overloaded function.
redoAvailable function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.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
revision function (self) -> int X.revision() -> int
rootFrame function (self) -> Any X.rootFrame() -> PythonQt.QtGui.QTextFrame
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
setDefaultCursorMoveStyle function (self, style: Any) -> None Sets the default cursor movement style to the given style.
setDefaultFont function (self, font: Any) -> None Sets the default font to use in the document layout.
setDefaultStyleSheet function (self, sheet: str) -> None
setDefaultTextOption function (self, option: Any) -> None Sets the default text option to option.
setDocumentLayout function (self, layout: Any) -> None Sets the document to use the given layout.
setDocumentMargin function (self, margin: float) -> None
setHtml function (self, html: str) -> None Replaces the entire contents of the document with the given HTML-formatted text in the html string.
setIndentWidth function (self, width: float) -> None Sets the width used for text list and text block indenting.
setMaximumBlockCount function (self, maximum: int) -> None
setMetaInformation function (self, info: Any, arg__2: str) -> None X.setMetaInformation(info, arg__2)
setModified function (self, m: bool) -> None
setObjectName function (self, name: Any) -> Any (shared captured text)
setPageSize function (self, size: Any) -> None
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.
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setTextWidth function (self, width: float) -> None
setUndoRedoEnabled function (self, enable: bool) -> None
setUseDesignMetrics function (self, b: bool) -> None
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
size attribute QSizeF Returns the actual size of the document.
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.
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
toPlainText function (self) -> str X.toPlainText() -> str
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.
undoAvailable function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QTextDocument.undoAvailable; argument details are not documented.
undoCommandAdded function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QTextDocument.undoCommandAdded; argument details are not documented.
undoRedoEnabled attribute Any This property holds whether undo/redo are enabled for this document
useDesignMetrics attribute bool This property holds whether the document uses design metrics of fonts to improve the accuracy of text layout