QAbstractTextDocumentLayout 类是用于实现 QTextDocument 自定义布局的抽象基类。 更多...
头: | #include <QAbstractTextDocumentLayout> |
CMake: |
find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
继承: | QObject |
继承者: | QPlainTextDocumentLayout |
注意: 此类的所有函数 可重入 .
struct | PaintContext |
struct | Selection |
QAbstractTextDocumentLayout (QTextDocument * document ) | |
QString | anchorAt (const QPointF & position ) const |
virtual QRectF | blockBoundingRect (const QTextBlock & block ) const = 0 |
QTextBlock | blockWithMarkerAt (const QPointF & pos ) const |
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) |
void | documentSizeChanged (const QSizeF & newSize ) |
void | pageCountChanged (int newPages ) |
void | update (const QRectF & rect = QRectF(0., 0., 1000000000., 1000000000.)) |
void | updateBlock (const QTextBlock & block ) |
virtual void | documentChanged (int position , int charsRemoved , int charsAdded ) = 0 |
virtual void | drawInlineObject (QPainter * painter , const QRectF & rect , QTextInlineObject object , int posInDocument , const QTextFormat & format ) |
QTextCharFormat | format (int position ) |
virtual void | positionInlineObject (QTextInlineObject item , int posInDocument , const QTextFormat & format ) |
virtual void | resizeInlineObject (QTextInlineObject item , int posInDocument , const QTextFormat & format ) |
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 对象采用 setDocumentLayout() 函数。
You can insert custom objects into a QTextDocument ;见 QTextObjectInterface 类描述了解细节。
另请参阅 QTextObjectInterface .
创建新的文本文档布局为给定 document .
[signal]
void
QAbstractTextDocumentLayout::
documentSizeChanged
(const
QSizeF
&
newSize
)
This signal is emitted when the size of the document layout changes to newSize .
子类化的 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.
另请参阅 documentSize ().
[signal]
void
QAbstractTextDocumentLayout::
pageCountChanged
(
int
newPages
)
This signal is emitted when the number of pages in the layout changes; newPages is the updated page count.
子类化的 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.
另请参阅 pageCount ().
[signal]
void
QAbstractTextDocumentLayout::
update
(const
QRectF
&
rect
= QRectF(0., 0., 1000000000., 1000000000.))
此信号被发射当矩形 rect 已更新。
子类化的 QAbstractTextDocumentLayout should emit this signal when the layout of the contents change in order to repaint.
[signal]
void
QAbstractTextDocumentLayout::
updateBlock
(const
QTextBlock
&
block
)
此信号被发射当指定 block 已更新。
子类化的 QAbstractTextDocumentLayout should emit this signal when the layout of block has changed in order to repaint.
Returns the reference of the anchor the given position ,或空字符串若该点不存在锚点。
[pure virtual]
QRectF
QAbstractTextDocumentLayout::
blockBoundingRect
(const
QTextBlock
&
block
) const
Returns the bounding rectangle of block .
[since 5.14]
QTextBlock
QAbstractTextDocumentLayout::
blockWithMarkerAt
(const
QPointF
&
pos
) const
Returns the block (probably a list item) whose marker is found at the given position pos .
该函数在 Qt 5.14 引入。
Returns the text document that this layout is operating on.
[pure virtual protected]
void
QAbstractTextDocumentLayout::
documentChanged
(
int
position
,
int
charsRemoved
,
int
charsAdded
)
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 ,和 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:
另请参阅 QTextLayout .
[pure virtual]
QSizeF
QAbstractTextDocumentLayout::
documentSize
() const
返回文档布局的总大小。
This information can be used by display widgets to update their scroll bars correctly.
另请参阅 documentSizeChanged () 和 QTextDocument::pageSize .
[pure virtual]
void
QAbstractTextDocumentLayout::
draw
(
QPainter
*
painter
, const
QAbstractTextDocumentLayout::PaintContext
&
context
)
Draws the layout with the given painter 使用给定 context .
[virtual protected]
void
QAbstractTextDocumentLayout::
drawInlineObject
(
QPainter
*
painter
, const
QRectF
&
rect
,
QTextInlineObject
object
,
int
posInDocument
, const
QTextFormat
&
format
)
调用此函数以绘制内联对象 object ,采用给定 painter 在矩形内指定通过 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.
另请参阅 draw ().
[protected]
QTextCharFormat
QAbstractTextDocumentLayout::
format
(
int
position
)
Returns the character format that is applicable at the given position .
[since 5.8]
QTextFormat
QAbstractTextDocumentLayout::
formatAt
(const
QPointF
&
pos
) const
Returns the text format at the given position pos .
该函数在 Qt 5.8 引入。
[pure virtual]
QRectF
QAbstractTextDocumentLayout::
frameBoundingRect
(
QTextFrame
*
frame
) const
Returns the bounding rectangle of frame .
Returns a handler for objects of the given objectType .
[pure virtual]
int
QAbstractTextDocumentLayout::
hitTest
(const
QPointF
&
point
,
Qt::HitTestAccuracy
accuracy
) const
Returns the cursor position for the given point 采用指定 accuracy . Returns -1 if no valid cursor position was found.
[since 5.8]
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.
该函数在 Qt 5.8 引入。
[pure virtual]
int
QAbstractTextDocumentLayout::
pageCount
() const
Returns the number of pages contained in the layout.
另请参阅 pageCountChanged ().
Returns the paint device used to render the document's layout.
另请参阅 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.
另请参阅 drawInlineObject ().
注册给定 component as a handler for items of the given objectType .
注意: 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.
Sets the paint device used for rendering the document's layout to the given device .
另请参阅 paintDevice ().
[since 5.2]
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 未指定。
该函数在 Qt 5.2 引入。