QTextDocumentWriter

The QTextDocumentWriter class provides a format-independent interface for writing a QTextDocument to files or other devices. More

Inheritance diagram of PySide2.QtGui.QTextDocumentWriter

New in version 4.5.

Synopsis

Functions

Static functions

Detailed Description

To write a document, construct a QTextDocumentWriter object 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 using setFormat() later.

Call write() to write the document to the device. If the document is successfully written, this function returns true . However, if an error occurs when writing the document, it will return false.

Call supportedDocumentFormats() for a list of formats that QTextDocumentWriter can 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 QTextDocumentWriter

QTextDocumentWriter(device, format)

QTextDocumentWriter(fileName[, format=QByteArray()])

param format

QByteArray

param device

QIODevice

param fileName

unicode

Constructs an empty QTextDocumentWriter object. Before writing, you must call setFormat() to set a document format, then setDevice() or setFileName() .

PySide2.QtGui.QTextDocumentWriter.codec()
Return type

QTextCodec

Returns the codec that is currently assigned to the writer.

See also

setCodec()

PySide2.QtGui.QTextDocumentWriter.device()
Return type

QIODevice

Returns the device currently assigned, or None if no device has been assigned.

See also

setDevice()

PySide2.QtGui.QTextDocumentWriter.fileName()
Return type

unicode

If the currently assigned device is a QFile , or if setFileName() has been called, this function returns the name of the file to be written to. In all other cases, it returns an empty string.

PySide2.QtGui.QTextDocumentWriter.format()
Return type

QByteArray

Returns the format used for writing documents.

See also

setFormat()

PySide2.QtGui.QTextDocumentWriter.setCodec(codec)
Parameters

codecQTextCodec

Sets the codec for this stream to codec . The codec is used for encoding any data that is written. By default, QTextDocumentWriter uses UTF-8.

See also

codec()

PySide2.QtGui.QTextDocumentWriter.setDevice(device)
Parameters

deviceQIODevice

Sets the writer’s device to the device specified. If a device has already been set, the old device is removed but otherwise left unchanged.

If the device is not already open, QTextDocumentWriter will attempt to open the device in WriteOnly mode by calling open().

Note

This will not work for certain devices, such as QProcess , QTcpSocket and QUdpSocket , where some configuration is required before the device can be opened.

PySide2.QtGui.QTextDocumentWriter.setFileName(fileName)
Parameters

fileName – unicode

Sets the name of the file to be written to fileName . Internally, QTextDocumentWriter will create a QFile and open it in WriteOnly mode, and use this file when writing the document.

PySide2.QtGui.QTextDocumentWriter.setFormat(format)
Parameters

formatQByteArray

Sets the format used to write documents to the format specified. format is 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 formats QTextDocumentWriter supports.

See also

format()

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

ODF

OpenDocument Format

See also

setFormat()

PySide2.QtGui.QTextDocumentWriter.write(document)
Parameters

documentQTextDocument

Return type

bool

Writes the given document to the assigned device or file and returns true if successful; otherwise returns false .

PySide2.QtGui.QTextDocumentWriter.write(fragment)
Parameters

fragmentQTextDocumentFragment

Return type

bool