QTextDocumentWriter¶
The
QTextDocumentWriterclass provides a format-independent interface for writing aQTextDocumentto files or other devices. More…

New in version 4.5.
Synopsis¶
Functions¶
Static functions¶
def
supportedDocumentFormats()
Detailed Description¶
To write a document, construct a
QTextDocumentWriterobject with either a file name or a device object, and specify the document format to be written. You can construct a writer and set the format usingsetFormat()later.Call
write()to write the document to the device. If the document is successfully written, this function returnstrue. However, if an error occurs when writing the document, it will return false.Call
supportedDocumentFormats()for a list of formats thatQTextDocumentWritercan write.Since the capabilities of the supported output formats vary considerably, the writer simply outputs the appropriate subset of objects for each format. This typically includes the formatted text and images contained in a document.
- class PySide2.QtGui.QTextDocumentWriter¶
PySide2.QtGui.QTextDocumentWriter(device, format)
PySide2.QtGui.QTextDocumentWriter(fileName[, format=QByteArray()])
- param format:
- param device:
- param fileName:
str
Constructs an empty
QTextDocumentWriterobject. Before writing, you must callsetFormat()to set a document format, thensetDevice()orsetFileName().
- PySide2.QtGui.QTextDocumentWriter.codec()¶
- Return type:
Returns the codec that is currently assigned to the writer.
See also
- PySide2.QtGui.QTextDocumentWriter.device()¶
- Return type:
Returns the device currently assigned, or
Noneif no device has been assigned.See also
- PySide2.QtGui.QTextDocumentWriter.fileName()¶
- Return type:
str
If the currently assigned device is a
QFile, or ifsetFileName()has been called, this function returns the name of the file to be written to. In all other cases, it returns an empty string.See also
- PySide2.QtGui.QTextDocumentWriter.format()¶
- Return type:
Returns the format used for writing documents.
See also
- PySide2.QtGui.QTextDocumentWriter.setCodec(codec)¶
- Parameters:
codec –
PySide2.QtCore.QTextCodec
Sets the codec for this stream to
codec. The codec is used for encoding any data that is written. By default,QTextDocumentWriteruses UTF-8.See also
- PySide2.QtGui.QTextDocumentWriter.setDevice(device)¶
- Parameters:
device –
PySide2.QtCore.QIODevice
Sets the writer’s device to the
devicespecified. If a device has already been set, the old device is removed but otherwise left unchanged.If the device is not already open,
QTextDocumentWriterwill attempt to open the device inWriteOnlymode by calling open().Note
This will not work for certain devices, such as
QProcess,QTcpSocketandQUdpSocket, where some configuration is required before the device can be opened.See also
- PySide2.QtGui.QTextDocumentWriter.setFileName(fileName)¶
- Parameters:
fileName – str
Sets the name of the file to be written to
fileName. Internally,QTextDocumentWriterwill create aQFileand open it inWriteOnlymode, and use this file when writing the document.See also
- PySide2.QtGui.QTextDocumentWriter.setFormat(format)¶
- Parameters:
format –
PySide2.QtCore.QByteArray
Sets the format used to write documents to the
formatspecified.formatis a case insensitive text string. For example:QTextDocumentWriter writer; writer.setFormat("odf"); // same as writer.setFormat("ODF");
You can call
supportedDocumentFormats()for the full list of formatsQTextDocumentWritersupports.See also
- static PySide2.QtGui.QTextDocumentWriter.supportedDocumentFormats()¶
- Return type:
Returns the list of document formats supported by
QTextDocumentWriter.By default, Qt can write the following formats:
Format
Description
plaintext
Plain text
HTML
HyperText Markup Language
markdown
Markdown (CommonMark or GitHub dialects)
ODF
OpenDocument Format
See also
- PySide2.QtGui.QTextDocumentWriter.write(document)¶
- Parameters:
document –
PySide2.QtGui.QTextDocument- Return type:
bool
Writes the given
documentto the assigned device or file and returnstrueif successful; otherwise returnsfalse.
- PySide2.QtGui.QTextDocumentWriter.write(fragment)
- Parameters:
fragment –
PySide2.QtGui.QTextDocumentFragment- Return type:
bool
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.