Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QTextDocument Class Reference

#include <qtextdocument.h>

Inheritance diagram for QTextDocument:


List of all members.

Detailed Description

The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit.

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 can be obtained by calling the 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.

See also:
QTextCursor QTextEdit Rich Text Processing

Definition at line 88 of file qtextdocument.h.

Public Types

enum  FindFlag { FindBackward = 0x00001, FindCaseSensitively = 0x00002, FindWholeWords = 0x00004 }
enum  MetaInformation { DocumentTitle }
enum  ResourceType { HtmlResource = 1, ImageResource = 2, StyleSheetResource = 3, UserResource = 100 }

Public Slots

void appendUndoItem (QAbstractUndoItem *)
void deleteLater ()
void redo ()
void setModified (bool m=true)
void undo ()


void contentsChange (int from, int charsRemoves, int charsAdded)
void contentsChanged ()
void cursorPositionChanged (const QTextCursor &cursor)
void destroyed (QObject *=0)
void modificationChanged (bool m)
void redoAvailable (bool)
void undoAvailable (bool)

Public Member Functions

void addResource (int type, const QUrl &name, const QVariant &resource)
void adjustSize ()
QVector< QTextFormatallFormats () const
QTextBlock begin () const
int blockCount () const
bool blockSignals (bool b)
const QObjectListchildren () const
virtual void clear ()
QTextDocumentclone (QObject *parent=0) const
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
QFont defaultFont () const
QString defaultStyleSheet () const
bool disconnect (const QObject *receiver, const char *member=0)
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
QTextDocumentPrivate * docHandle () const
QAbstractTextDocumentLayoutdocumentLayout () const
void drawContents (QPainter *painter, const QRectF &rect=QRectF())
void dumpObjectInfo ()
void dumpObjectTree ()
QList< QByteArraydynamicPropertyNames () const
QTextBlock end () const
virtual bool event (QEvent *)
virtual bool eventFilter (QObject *, QEvent *)
QTextCursor find (const QRegExp &expr, const QTextCursor &from, FindFlags options=0) const
QTextCursor find (const QRegExp &expr, int from=0, FindFlags options=0) const
QTextCursor find (const QString &subString, const QTextCursor &from, FindFlags options=0) const
QTextCursor find (const QString &subString, int from=0, FindFlags options=0) const
QTextBlock findBlock (int pos) const
template<typename T>
findChild (const QString &name=QString()) const
template<typename T>
QList< T > findChildren (const QRegExp &re) const
template<typename T>
QList< T > findChildren (const QString &name=QString()) const
QTextFrameframeAt (int pos) const
qreal idealWidth () const
bool inherits (const char *classname) const
void installEventFilter (QObject *)
bool isEmpty () const
bool isModified () const
bool isRedoAvailable () const
bool isUndoAvailable () const
bool isUndoRedoEnabled () const
bool isWidgetType () const
void killTimer (int id)
void markContentsDirty (int from, int length)
int maximumBlockCount () const
QString metaInformation (MetaInformation info) const
void moveToThread (QThread *thread)
QTextObjectobject (int objectIndex) const
QTextObjectobjectForFormat (const QTextFormat &) const
QString objectName () const
int pageCount () const
QSizeF pageSize () const
QObjectparent () const
void print (QPrinter *printer) const
QVariant property (const char *name) const
 QTextDocument (const QString &text, QObject *parent=0)
 QTextDocument (QObject *parent=0)
void redo (QTextCursor *cursor)
void removeEventFilter (QObject *)
QVariant resource (int type, const QUrl &name) const
QTextFramerootFrame () const
void setDefaultFont (const QFont &font)
void setDefaultStyleSheet (const QString &sheet)
void setDocumentLayout (QAbstractTextDocumentLayout *layout)
void setHtml (const QString &html)
void setMaximumBlockCount (int maximum)
void setMetaInformation (MetaInformation info, const QString &)
void setObjectName (const QString &name)
void setPageSize (const QSizeF &size)
void setParent (QObject *)
void setPlainText (const QString &text)
bool setProperty (const char *name, const QVariant &value)
void setTextWidth (qreal width)
void setUndoRedoEnabled (bool enable)
void setUseDesignMetrics (bool b)
void setUserData (uint id, QObjectUserData *data)
bool signalsBlocked () const
QSizeF size () const
int startTimer (int interval)
qreal textWidth () const
QThreadthread () const
QString toHtml (const QByteArray &encoding=QByteArray()) const
QString toPlainText () const
void undo (QTextCursor *cursor)
bool useDesignMetrics () const
QObjectUserData * userData (uint id) const
 ~QTextDocument ()

Static Public Member Functions

static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
static uint registerUserData ()

Protected Member Functions

virtual void childEvent (QChildEvent *)
virtual void connectNotify (const char *signal)
virtual QTextObjectcreateObject (const QTextFormat &f)
virtual void customEvent (QEvent *)
virtual void disconnectNotify (const char *signal)
virtual QVariant loadResource (int type, const QUrl &name)
 QTextDocument (QTextDocumentPrivate &dd, QObject *parent)
int receivers (const char *signal) const
QObjectsender () const
virtual void timerEvent (QTimerEvent *)

Protected Attributes

QObjectData * d_ptr

Static Protected Attributes

static const QMetaObject staticQtMetaObject


int blockCount
QFont defaultFont
 the default font used to display the document's text
QString defaultStyleSheet
int maximumBlockCount
 Specifies the limit for blocks in the document.
bool modified
 whether the document has been modified by the user
QString objectName
 the name of this object
QSizeF pageSize
 the page size that should be used for laying out the document
QSizeF size
qreal textWidth
bool undoRedoEnabled
 whether undo/redo are enabled for this document
bool useDesignMetrics


class QApplication
class QApplicationPrivate
class QCoreApplication
class QCoreApplicationPrivate
struct QMetaObject
class QThreadData
class QWidget

Related Functions

(Note that these are not member functions.)

qFindChild (const QObject *obj, const QString &name=QString(), T dummy=0)
qFindChild (const QObject *obj, const QString &name)
QList< T > qFindChildren (const QObject *obj, const QString &name=QString(), T dummy=0)
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
QList< T > qFindChildren (const QObject *obj, const QString &name)
T * qobject_cast (QObject *object)
void * qt_find_obj_child (QObject *parent, const char *type, const QString &name)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index