QAbstractTextDocumentLayout Class

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

Header: #include <QAbstractTextDocumentLayout>
qmake: QT += gui
Inherits: QObject

Note: All functions in this class are reentrant.

Public Types

class PaintContext
class Selection

Public Functions

QAbstractTextDocumentLayout(QTextDocument *document)
QString anchorAt(const QPointF &pos) const
virtual QRectF blockBoundingRect(const QTextBlock &block) const = 0
QTextDocument *document() const
virtual QSizeF documentSize() const = 0
virtual void draw(QPainter *painter, const QAbstractTextDocumentLayout::PaintContext &context) = 0
QTextFormat formatAt(const QPointF &pos) const
virtual QRectF frameBoundingRect(QTextFrame *frame) const = 0
QTextObjectInterface *handlerForObject(int objectType) const
virtual int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const = 0
QString imageAt(const QPointF &pos) const
virtual int pageCount() const = 0
QPaintDevice *paintDevice() const
void registerHandler(int objectType, QObject *component)
void setPaintDevice(QPaintDevice *device)
void unregisterHandler(int objectType, QObject *component = nullptr)
  • 31 public functions inherited from QObject

Signals

void documentSizeChanged(const QSizeF &newSize)
void pageCountChanged(int newPages)
void update(const QRectF & = QRectF(0., 0., 1000000000., 1000000000.))
void updateBlock(const QTextBlock &block)

Static Public Members

const QMetaObject staticMetaObject
  • 9 static public members inherited from QObject

Protected Functions

virtual void documentChanged(int from, int charsRemoved, int charsAdded) = 0
virtual void drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format)
QTextCharFormat format(int pos)
virtual void positionInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format)
virtual void resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format)
  • 9 protected functions inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject

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.

See also QTextObjectInterface.

Member Function Documentation

QAbstractTextDocumentLayout::QAbstractTextDocumentLayout(QTextDocument *document)

Creates a new text document layout for the given document.

QString QAbstractTextDocumentLayout::anchorAt(const QPointF &pos) const

[pure virtual] QRectF QAbstractTextDocumentLayout::blockBoundingRect(const QTextBlock &block) const

QTextDocument *QAbstractTextDocumentLayout::document() const

Returns the text document that this layout is operating on.

[pure virtual protected] void QAbstractTextDocumentLayout::documentChanged(int from, int charsRemoved, int charsAdded)

[pure virtual] QSizeF QAbstractTextDocumentLayout::documentSize() const

[signal] void QAbstractTextDocumentLayout::documentSizeChanged(const QSizeF &newSize)

[pure virtual] void QAbstractTextDocumentLayout::draw(QPainter *painter, const QAbstractTextDocumentLayout::PaintContext &context)

[virtual protected] void QAbstractTextDocumentLayout::drawInlineObject(QPainter *painter, const QRectF &rect, QTextInlineObject object, int posInDocument, const QTextFormat &format)

[protected] QTextCharFormat QAbstractTextDocumentLayout::format(int pos)

QTextFormat QAbstractTextDocumentLayout::formatAt(const QPointF &pos) const

Returns the text format at the given position pos.

This function was introduced in Qt 5.8.

[pure virtual] QRectF QAbstractTextDocumentLayout::frameBoundingRect(QTextFrame *frame) const

QTextObjectInterface *QAbstractTextDocumentLayout::handlerForObject(int objectType) const

Returns a handler for objects of the given objectType.

[pure virtual] int QAbstractTextDocumentLayout::hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const

QString QAbstractTextDocumentLayout::imageAt(const QPointF &pos) const

Returns the source of the image at the given position pos, or an empty string if no image exists at that point.

This function was introduced in Qt 5.8.

[pure virtual] int QAbstractTextDocumentLayout::pageCount() const

[signal] void QAbstractTextDocumentLayout::pageCountChanged(int newPages)

QPaintDevice *QAbstractTextDocumentLayout::paintDevice() const

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

See also setPaintDevice().

[virtual protected] void QAbstractTextDocumentLayout::positionInlineObject(QTextInlineObject item, int posInDocument, const 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().

void QAbstractTextDocumentLayout::registerHandler(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.

The text document layout does not take ownership of component.

[virtual protected] void QAbstractTextDocumentLayout::resizeInlineObject(QTextInlineObject item, int posInDocument, const 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.

void QAbstractTextDocumentLayout::setPaintDevice(QPaintDevice *device)

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

See also paintDevice().

void QAbstractTextDocumentLayout::unregisterHandler(int objectType, QObject *component = nullptr)

Unregisters the given component as a handler for items of the given objectType, or any handler if the component is not specified.

This function was introduced in Qt 5.2.

[signal] void QAbstractTextDocumentLayout::update(const QRectF & = QRectF(0., 0., 1000000000., 1000000000.))

[signal] void QAbstractTextDocumentLayout::updateBlock(const QTextBlock &block)