|  | Home · All Classes · Modules

# QTextFrame Class Reference
[QtGui module]

The QTextFrame class represents a frame in a QTextDocument. More...

Inherits QTextObject.

Inherited by QTextTable.

### Types

- class iterator

### Methods

- __init__ (self, QTextDocument doc)
- iterator begin (self)
- list-of-QTextFrame childFrames (self)
- iterator end (self)
- QTextCursor firstCursorPosition (self)
- int firstPosition (self)
- QTextFrameFormat frameFormat (self)
- QTextCursor lastCursorPosition (self)
- int lastPosition (self)
- QTextFrame parentFrame (self)
- setFrameFormat (self, QTextFrameFormat aformat)

## Detailed Description

The QTextFrame class represents a frame in a QTextDocument.

Text frames provide structure for the text in a document. They are used as generic containers for other document elements. Frames are usually created by using QTextCursor.insertFrame().

Frames can be used to create hierarchical structures in rich text documents. Each document has a root frame (QTextDocument.rootFrame()), and each frame beneath the root frame has a parent frame and a (possibly empty) list of child frames. The parent frame can be found with parentFrame(), and the childFrames() function provides a list of child frames.

Each frame contains at least one text block to enable text cursors to insert new document elements within. As a result, the QTextFrame.iterator class is used to traverse both the blocks and child frames within a given frame. The first and last child elements in the frame can be found with begin() and end().

A frame also has a format (specified using QTextFrameFormat) which can be set with setFormat() and read with format().

Text cursors can be obtained that point to the first and last valid cursor positions within a frame; use the firstCursorPosition() and lastCursorPosition() functions for this. The frame's extent in the document can be found with firstPosition() and lastPosition().

You can iterate over a frame's contents using the QTextFrame.iterator class: this provides read-only access to its internal list of text blocks and child frames.

## Method Documentation

### QTextFrame.__init__ (self, QTextDocument doc)

Creates a new empty frame for the text document.

### iterator QTextFrame.begin (self)

Returns an iterator pointing to the first document element inside the frame. Please see the document STL-style-Iterators for more information.

See also end().

### list-of-QTextFrame QTextFrame.childFrames (self)

Returns a (possibly empty) list of the frame's child frames.

See also parentFrame().

### iterator QTextFrame.end (self)

Returns an iterator pointing to the position past the last document element inside the frame. Please see the document STL-Style Iterators for more information.

See also begin().

### QTextCursor QTextFrame.firstCursorPosition (self)

Returns the first cursor position inside the frame.

See also lastCursorPosition(), firstPosition(), and lastPosition().

### int QTextFrame.firstPosition (self)

Returns the first document position inside the frame.

See also lastPosition(), firstCursorPosition(), and lastCursorPosition().

### QTextFrameFormat QTextFrame.frameFormat (self)

Returns the frame's format.

See also setFrameFormat().

### QTextCursor QTextFrame.lastCursorPosition (self)

Returns the last cursor position inside the frame.

See also firstCursorPosition(), firstPosition(), and lastPosition().

### int QTextFrame.lastPosition (self)

Returns the last document position inside the frame.

See also firstPosition(), firstCursorPosition(), and lastCursorPosition().

### QTextFrame QTextFrame.parentFrame (self)

Returns the frame's parent frame. If the frame is the root frame of a document, this will return 0.

See also childFrames() and QTextDocument.rootFrame().

### QTextFrame.setFrameFormat (self, QTextFrameFormat aformat)

Sets the frame's format.

See also frameFormat().