Home · All Classes · Modules

QAbstractTextDocumentLayout Class Reference
[QtGui module]

The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for QTextDocuments. More...

Inherits QObject.

Inherited by QPlainTextDocumentLayout.

Types

Methods

Qt Signals


Detailed Description

The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for QTextDocuments.

The standard layout provided by Qt can handle simple word processing including inline images, lists and tables.

Some applications, e.g., a word processor or a DTP application might need more features than the ones provided by Qt's layout engine, in which case you can subclass QAbstractTextDocumentLayout to provide custom layout behavior for your text documents.

An instance of the QAbstractTextDocumentLayout subclass can be installed on a QTextDocument object with the setDocumentLayout() function.

You can insert custom objects into a QTextDocument; see the QTextObjectInterface class description for details.


Method Documentation

QAbstractTextDocumentLayout.__init__ (self, QTextDocument doc)

Creates a new text document layout for the given document.

QString QAbstractTextDocumentLayout.anchorAt (self, QPointF pos)

Returns the reference of the anchor the given position, or an empty string if no anchor exists at that point.

QRectF QAbstractTextDocumentLayout.blockBoundingRect (self, QTextBlock block)

This method is abstract and should be reimplemented in any sub-class.

Returns the bounding rectangle of block.

QTextDocument QAbstractTextDocumentLayout.document (self)

Returns the text document that this layout is operating on.

QAbstractTextDocumentLayout.documentChanged (self, int from, int charsRemoved, int charsAdded)

This method is abstract and should be reimplemented in any sub-class.

This function is called whenever the contents of the document change. A change occurs when text is inserted, removed, or a combination of these two. The change is specified by position, charsRemoved, and charsAdded corresponding to the starting character position of the change, the number of characters removed from the document, and the number of characters added.

For example, when inserting the text "Hello" into an empty document, charsRemoved would be 0 and charsAdded would be 5 (the length of the string).

Replacing text is a combination of removing and inserting. For example, if the text "Hello" gets replaced by "Hi", charsRemoved would be 5 and charsAdded would be 2.

For subclasses of QAbstractTextDocumentLayout, this is the central function where a large portion of the work to lay out and position document contents is done.

For example, in a subclass that only arranges blocks of text, an implementation of this function would have to do the following:

See also QTextLayout.

QSizeF QAbstractTextDocumentLayout.documentSize (self)

This method is abstract and should be reimplemented in any sub-class.

Returns the total size of the document's layout.

This information can be used by display widgets to update their scroll bars correctly.

See also documentSizeChanged() and QTextDocument.pageSize.

QAbstractTextDocumentLayout.draw (self, QPainter painter, PaintContext context)

This method is abstract and should be reimplemented in any sub-class.

Draws the layout with the given painter using the given context.

QAbstractTextDocumentLayout.drawInlineObject (self, QPainter painter, QRectF rect, QTextInlineObject object, int posInDocument, QTextFormat format)

This function is called to draw the inline object, object, with the given painter within the rectangle specified by rect using the specified text format.

posInDocument specifies the position of the object within the document.

The default implementation calls drawObject() on the object handlers. This function is called only within Qt. Subclasses can reimplement this function to customize the drawing of inline objects.

See also draw().

QTextCharFormat QAbstractTextDocumentLayout.format (self, int pos)

Returns the character format that is applicable at the given position.

QRectF QAbstractTextDocumentLayout.frameBoundingRect (self, QTextFrame frame)

This method is abstract and should be reimplemented in any sub-class.

Returns the bounding rectangle of frame.

QTextObjectInterface QAbstractTextDocumentLayout.handlerForObject (self, int objectType)

Returns a handler for objects of the given objectType.

int QAbstractTextDocumentLayout.hitTest (self, QPointF point, Qt.HitTestAccuracy accuracy)

This method is abstract and should be reimplemented in any sub-class.

Returns the cursor postion for the given point with the specified accuracy. Returns -1 if no valid cursor position was found.

int QAbstractTextDocumentLayout.pageCount (self)

This method is abstract and should be reimplemented in any sub-class.

Returns the number of pages contained in the layout.

See also pageCountChanged().

QPaintDevice QAbstractTextDocumentLayout.paintDevice (self)

Returns the paint device used to render the document's layout.

See also setPaintDevice().

QAbstractTextDocumentLayout.positionInlineObject (self, QTextInlineObject item, int posInDocument, QTextFormat format)

Lays out the inline object item using the given text format.

posInDocument specifies the position of the object within the document.

The default implementation does nothing. This function is called only within Qt. Subclasses can reimplement this function to customize the position of inline objects.

See also drawInlineObject().

QAbstractTextDocumentLayout.registerHandler (self, int objectType, QObject component)

Registers the given component as a handler for items of the given objectType.

Note: registerHandler() has to be called once for each object type. This means that there is only one handler for multiple replacement characters of the same object type.

QAbstractTextDocumentLayout.resizeInlineObject (self, QTextInlineObject item, int posInDocument, QTextFormat format)

Sets the size of the inline object item corresponding to the text format.

posInDocument specifies the position of the object within the document.

The default implementation resizes the item to the size returned by the object handler's intrinsicSize() function. This function is called only within Qt. Subclasses can reimplement this function to customize the resizing of inline objects.

QAbstractTextDocumentLayout.setPaintDevice (self, QPaintDevice device)

Sets the paint device used for rendering the document's layout to the given device.

See also paintDevice().


Qt Signal Documentation

void documentSizeChanged (const ::QSizeF&)

This is the default overload of this signal.

This signal is emitted when the size of the document layout changes to newSize.

Subclasses of QAbstractTextDocumentLayout should emit this signal when the document's entire layout size changes. This signal is useful for widgets that display text documents since it enables them to update their scroll bars correctly.

See also documentSize().

void pageCountChanged (int)

This is the default overload of this signal.

This signal is emitted when the number of pages in the layout changes; newPages is the updated page count.

Subclasses of QAbstractTextDocumentLayout should emit this signal when the number of pages in the layout has changed. Changes to the page count are caused by changes to the layout or the document content itself.

See also pageCount().

void update (const ::QRectF& = QRectF (0,0,1e+09,1e+09))

This is the default overload of this signal.

This signal is emitted when the rectangle rect has been updated.

Subclasses of QAbstractTextDocumentLayout should emit this signal when the layout of the contents change in order to repaint.

void updateBlock (const ::QTextBlock&)

This is the default overload of this signal.

This signal is emitted when the specified block has been updated.

Subclasses of QAbstractTextDocumentLayout should emit this signal when the layout of block has changed in order to repaint.

This function was introduced in Qt 4.4.


PyQt 4.12 for X11Copyright © Riverbank Computing Ltd and The Qt Company 2015Qt 4.8.7