QAbstractTextDocumentLayout Class Reference

[QtGui module]

该QAbstractTextDocumentLayout类是用于实现自定义布局QTextDocuments的抽象基类。More…

继承QObject

通过继承QPlainTextDocumentLayout

Types

  • class **[PaintContext]($docs-index.htm)**
  • class **[Selection]($docs-index.htm)**

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)
  • QTextObjectInterface handlerForObject (self, int objectType)
  • int hitTest (self, QPointF point, Qt.HitTestAccuracy accuracy)
  • int pageCount (self)
  • QPaintDevice paintDevice (self)
  • positionInlineObject (self, QTextInlineObject item, int posInDocument, QTextFormat format)
  • registerHandler (self, int objectType, QObject component)
  • 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

该QAbstractTextDocumentLayout类是用于实现自定义布局QTextDocuments的抽象基类。

Qt提供了标准布局可以处理简单的文字处理,包括内嵌图片,列表和表格。

有些应用程序,如文字处理器或DTP应用程序可能需要比Qt的布局引擎提供的,那些更多的功能,在这种情况下,你可以继承QAbstractTextDocumentLayout为您的文本文档提供自定义布局行为。

该QAbstractTextDocumentLayout子类的实例可以在安装QTextDocument与对象setDocumentLayout()功能。

您可以将自定义对象成QTextDocument,见QTextObjectInterface类描述的细节。


Method Documentation

  1. QAbstractTextDocumentLayout.__init__ (self, QTextDocument doc)

创建用于指定一个新的文本文档布局document

  1. QString QAbstractTextDocumentLayout.anchorAt (self, QPointF pos)

返回锚的参考给定的position,或者如果没有锚存在于该点一个空字符串。

  1. QRectF QAbstractTextDocumentLayout.blockBoundingRect (self, QTextBlock block)

[

这种方法是抽象的,应在任何子类中重新实现。

返回的边框block

](qrectf.html)

  1. QTextDocument QAbstractTextDocumentLayout.document (self)

[

返回此布局工作于文本文档。

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

这种方法是抽象的,应在任何子类中重新实现。

此功能被称为文档变化时的内容。当文本被插入,删除时,会发生变化,或这两种的组合。这种变化是通过指定positioncharsRemovedcharsAdded对应于该变化的开始字符的位置,从文档中删除的字符数,和字符的数量加入。

例如,进入一个空文档中插入文本“Hello ”时,charsRemoved将0和charsAdded将5(该字符串的长度)。

替换文本是删除和插入的组合。例如,如果文本“Hello ”被替换为“Hi” ,charsRemoved将是5和charsAdded将2 。

]($docs-qtextdocument.html)

对于子类QAbstractTextDocumentLayout,这是中央函数所在的工作的很大一部分来布置和位置文件的内容已经完成。

例如,在一个子类,只安排文本块,这个功能的实现就必须做到以下几点:

  • Determine the list of changed QTextBlock(s) using the parameters provided.
  • Each QTextBlock object’s corresponding QTextLayout object needs to be processed. You can access the QTextBlock‘s layout using the QTextBlock.layout() function. This processing should take the document’s page size into consideration.
  • If the total number of pages changed, the pageCountChanged() signal should be emitted.
  • If the total size changed, the documentSizeChanged() signal should be emitted.
  • The update() signal should be emitted to schedule a repaint of areas in the layout that require repainting.

See also QTextLayout

  1. QSizeF QAbstractTextDocumentLayout.documentSize (self)

[

这种方法是抽象的,应在任何子类中重新实现。

返回文档的布局的总大小。

这些信息可用于显示部件来正确地更新自己的滚动条。

]($docs-qsizef.html)

See also documentSizeChanged()和QTextDocument.pageSize

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

这种方法是抽象的,应在任何子类中重新实现。

绘制布局与给定的painter使用给定的context

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

调用此函数绘制内嵌的对象,object用给定的painter由指定的矩形内rect使用指定的文本format

posInDocument指定文件内的对象的位置。

默认实现调用drawObject ( )上的对象处理程序。这个函数被调用只在Qt的。子类可以重新实现此功能自定义内联对象的绘制。

See also draw( ) 。

  1. QTextCharFormat QAbstractTextDocumentLayout.format (self, int pos)

[

返回字符格式,适用于给定的position

](qtextcharformat.html)

  1. QRectF QAbstractTextDocumentLayout.frameBoundingRect (self, QTextFrame frame)

[

这种方法是抽象的,应在任何子类中重新实现。

返回的边框frame

](qrectf.html)

  1. QTextObjectInterface QAbstractTextDocumentLayout.handlerForObject (self, int objectType)

[

返回一个处理程序的特定对象objectType

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

这种方法是抽象的,应在任何子类中重新实现。

返回光标当前位置为给定的point用指定的accuracy。返回-1,如果没有有效的光标位置被发现。

  1. int QAbstractTextDocumentLayout.pageCount (self)

这种方法是抽象的,应在任何子类中重新实现。

返回中所包含的布局的页面数。

]($docs-qtextobjectinterface.html)

See also pageCountChanged( ) 。

  1. QPaintDevice QAbstractTextDocumentLayout.paintDevice (self)

[

返回用于呈现文档的布局绘制设备。

]($docs-qpaintdevice.html)

See also setPaintDevice( ) 。

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

勾画出嵌入对象item使用给定的文本format

posInDocument指定文件内的对象的位置。

默认实现不执行任何操作。这个函数被调用只在Qt的。子类可以重新实现此功能自定义内联对象的位置。

See also drawInlineObject( ) 。

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

注册给定的component作为一个处理程序的特定项目objectType

Note:registerHandler ( )为每个对象类型被调用一次。这意味着,只有一个对相同的对象类型的多个字符替换处理程序。

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

设置内嵌对象的大小item对应于文本format

posInDocument指定文件内的对象的位置。

默认实现调整大小的item由对象处理程序的intrinsicSize ( )函数返回的大小。这个函数被调用只在Qt的。子类可以重新实现此功能自定义内联对象的大小调整。

  1. QAbstractTextDocumentLayout.setPaintDevice (self, QPaintDevice device)

获取用于渲染文档的布局,以给定的涂料设备device

See also paintDevice( ) 。


Qt Signal Documentation

  1. void documentSizeChanged (const QSizeF&)

这是该信号的默认超载。

当文档布局的大小变更为这个信号被发射newSize

的子类QAbstractTextDocumentLayout应该发出这个信号,当文档的整个版面大小的变化。这个信号是显示文本文件,因为它使他们能够正确地更新自己的滚动条小工具非常有用。

See also documentSize( ) 。

  1. void pageCountChanged (int)

这是该信号的默认超载。

这个信号被发射时的布局变化的页数;newPages是更新页面计数。

的子类QAbstractTextDocumentLayout应该发出这个信号时的布局中的页面的数量发生了变化。被改变的页面数通过改变布局或文件内容本身引起的。

See also pageCount( ) 。

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

这是该信号的默认超载。

这个信号被发射时,矩形rect已被更新。

的子类QAbstractTextDocumentLayout应该发出这个信号,当内容的布局改变,以重新绘制。

  1. void updateBlock (const QTextBlock&)

这是该信号的默认超载。

指定时,这个信号被发射block已被更新。

的子类QAbstractTextDocumentLayout应该发出这个信号时的布局block为了重新绘制了变化。

此功能被引入Qt的4.4 。