|  | 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

- class PaintContext
- class Selection

### Methods

- __init__ (self, QTextDocument doc)
- QString anchorAt (self, QPointF pos)
- QRectF blockBoundingRect (self, QTextBlock block)
- QTextDocument document (self)
- documentChanged (self, int from, int charsRemoved, int charsAdded)
- QSizeF documentSize (self)
- draw (self, QPainter painter, PaintContext context)
- drawInlineObject (self, QPainter painter, QRectF rect, QTextInlineObject object, int posInDocument, QTextFormat format)
- QTextCharFormat format (self, int pos)
- QRectF frameBoundingRect (self, QTextFrame frame)
- int hitTest (self, QPointF point, Qt.HitTestAccuracy accuracy)
- int pageCount (self)
- QPaintDevice paintDevice (self)
- positionInlineObject (self, QTextInlineObject item, int posInDocument, QTextFormat format)
- resizeInlineObject (self, QTextInlineObject item, int posInDocument, QTextFormat format)
- setPaintDevice (self, QPaintDevice device)

### Qt Signals

- void documentSizeChanged (const QSizeF&)
- void pageCountChanged (int)
- void update (const QRectF& = QRectF(0,0,1e+09,1e+09))
- void updateBlock (const QTextBlock&)

## 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 layouts, 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 your own custom layout behavior for your text documents.

## 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 at 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 the two types of operation. The change is specified by position, charsRemoved, and charsAdded corresponding to the starting character position of the change, the number of character 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 the combination of removal and insertion. For example, if the text "Hello" gets replaced by "Hi", charsRemoved would be 5 and charsAdded would be 2.

### QSizeF QAbstractTextDocumentLayout.documentSize (self)

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

Returns the total size of the document. This is useful to display widgets since they can use the information 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 on the given painter with the given context.

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

Called to draw the inline object object on the given painter within the rectangle specified by rect using the text format specified by format. posInDocument specifies the position of the object within the document.

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 rectacle of frame. Returns the bounding rectangle of frame.

### 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 accuracy specified. Returns -1 to indicate failure 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 required by 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. The base class implementation does nothing. posInDocument specifies the position of the object within the document.

See also drawInlineObject().

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

Sets the size of the inline object item in accordance with the text format. posInDocument specifies the position of the object within the document.

### 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 signal is emitted when the size of the document changes. The new size is specified by newSize.

This information is useful to widgets that display text documents since it enables them to update their scroll bars correctly.

See also documentSize().

### void pageCountChanged (int)

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

Changes to the page count are due to the changes to the layout or the document content itself.

See also pageCount().

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

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

### void updateBlock (const QTextBlock&)

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

This function was introduced in Qt 4.4.