QTextDocumentWriterclass provides a format-independent interface for writing aQTextDocument到文件或其它设备。 更多 …
New in version 4.5.
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.调用
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.调用
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.
QTextDocumentWriter
¶
QTextDocumentWriter(device, format)
QTextDocumentWriter(fileName[, format=QByteArray()])
- param format
QByteArray- param device
QIODevice- param fileName
unicode
构造空
QTextDocumentWriter
object. Before writing, you must call
setFormat()
to set a document format, then
setDevice()
or
setFileName()
.
PySide2.QtGui.QTextDocumentWriter.
codec
(
)
¶
QTextCodec
Returns the codec that is currently assigned to the writer.
另请参阅
PySide2.QtGui.QTextDocumentWriter.
device
(
)
¶
QIODevice
Returns the device currently assigned, or
None
若没有设备被赋值。
另请参阅
PySide2.QtGui.QTextDocumentWriter.
fileName
(
)
¶
unicode
若目前赋值设备是
QFile
,或者若
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
(
)
¶
QByteArray
返回用于写文档的格式。
另请参阅
PySide2.QtGui.QTextDocumentWriter.
setCodec
(
codec
)
¶
codec
–
QTextCodec
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.
另请参阅
PySide2.QtGui.QTextDocumentWriter.
setDevice
(
device
)
¶
device
–
QIODevice
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.
若设备尚未打开,
QTextDocumentWriter
will attempt to open the device in
WriteOnly
mode by calling open().
注意
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
)
¶
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
)
¶
format
–
QByteArray
Sets the format used to write documents to the
format
指定。
format
is a case insensitive text string. For example:
QTextDocumentWriter writer;
writer.setFormat("odf"); // same as writer.setFormat("ODF");
可以调用
supportedDocumentFormats()
for the full list of formats
QTextDocumentWriter
支持。
另请参阅
PySide2.QtGui.QTextDocumentWriter.
supportedDocumentFormats
(
)
¶
Returns the list of document formats supported by
QTextDocumentWriter
.
By default, Qt can write the following formats:
|
格式 |
描述 |
|
plaintext |
纯文本 |
|
HTML |
HyperText Markup Language |
|
markdown |
Markdown (CommonMark or GitHub dialects) |
|
ODF |
OpenDocument Format |
另请参阅
PySide2.QtGui.QTextDocumentWriter.
write
(
document
)
¶
document
–
QTextDocument
bool
写入给定
document
to the assigned device or file and returns
true
若成功;否则返回
false
.
PySide2.QtGui.QTextDocumentWriter.
write
(
fragment
)
¶
fragment
–
QTextDocumentFragment
bool