QAbstractTextDocumentLayoutclass is an abstract base class used to implement custom layouts for QTextDocuments. 更多 …
def
anchorAt
(pos)
def
blockWithMarkerAt
(pos)
def
document
()
def
format
(pos)
def
formatAt
(pos)
def
formatIndex
(pos)
def
handlerForObject
(objectType)
def
imageAt
(pos)
def
paintDevice
()
def
registerHandler
(objectType, component)
def
setPaintDevice
(device)
def
unregisterHandler
(objectType[, component=None])
def
blockBoundingRect
(block)
def
documentChanged
(from, charsRemoved, charsAdded)
def
documentSize
()
def
draw
(painter, context)
def
drawInlineObject
(painter, rect, object, posInDocument, format)
def
frameBoundingRect
(frame)
def
hitTest
(point, accuracy)
def
pageCount
()
def
positionInlineObject
(item, posInDocument, format)
def
resizeInlineObject
(item, posInDocument, format)
def
documentSizeChanged
(newSize)
def
pageCountChanged
(newPages)
def
update
([arg__1=QRectF(0., 0., 1000000000., 1000000000.)])
def
updateBlock
(block)
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
QAbstractTextDocumentLayoutto provide custom layout behavior for your text documents.An instance of the
QAbstractTextDocumentLayoutsubclass can be installed on aQTextDocumentobject with thesetDocumentLayout()函数。You can insert custom objects into a
QTextDocument; see theQTextObjectInterface类描述了解细节。另请参阅
QAbstractTextDocumentLayout
(
doc
)
¶
- param doc
Creates a new text document layout for the given
document
.
PySide2.QtGui.QAbstractTextDocumentLayout.
anchorAt
(
pos
)
¶
pos
–
QPointF
unicode
Returns the reference of the anchor the given
position
,或空字符串若该点不存在锚点。
PySide2.QtGui.QAbstractTextDocumentLayout.
blockBoundingRect
(
block
)
¶
block
–
QTextBlock
QRectF
Returns the bounding rectangle of
block
.
PySide2.QtGui.QAbstractTextDocumentLayout.
blockWithMarkerAt
(
pos
)
¶
pos
–
QPointF
Returns the block (probably a list item) whose
marker
is found at the given position
pos
.
PySide2.QtGui.QAbstractTextDocumentLayout.
document
(
)
¶
Returns the text document that this layout is operating on.
PySide2.QtGui.QAbstractTextDocumentLayout.
documentChanged
(
from
,
charsRemoved
,
charsAdded
)
¶
from
–
int
charsRemoved
–
int
charsAdded
–
int
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:
Determine the list of changed
QTextBlock
(s) using the parameters provided.
每
QTextBlock
object’s corresponding
QTextLayout
object needs to be processed. You can access the
QTextBlock
‘s layout using the
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.
update()
signal should be emitted to schedule a repaint of areas in the layout that require repainting.
另请参阅
PySide2.QtGui.QAbstractTextDocumentLayout.
documentSize
(
)
¶
QSizeF
Returns the total size of the document’s layout.
This information can be used by display widgets to update their scroll bars correctly.
PySide2.QtGui.QAbstractTextDocumentLayout.
documentSizeChanged
(
newSize
)
¶
newSize
–
QSizeF
PySide2.QtGui.QAbstractTextDocumentLayout.
draw
(
painter
,
context
)
¶
painter
–
QPainter
context
–
PaintContext
Draws the layout with the given
painter
using the given
context
.
PySide2.QtGui.QAbstractTextDocumentLayout.
drawInlineObject
(
painter
,
rect
,
object
,
posInDocument
,
format
)
¶
painter
–
QPainter
rect
–
QRectF
object
–
QTextInlineObject
posInDocument
–
int
format
–
QTextFormat
This function is called to draw the inline object,
object
,采用给定
painter
within the rectangle specified by
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.
另请参阅
PySide2.QtGui.QAbstractTextDocumentLayout.
format
(
pos
)
¶
pos
–
int
Returns the character format that is applicable at the given
position
.
PySide2.QtGui.QAbstractTextDocumentLayout.
formatAt
(
pos
)
¶
pos
–
QPointF
Returns the text format at the given position
pos
.
PySide2.QtGui.QAbstractTextDocumentLayout.
formatIndex
(
pos
)
¶
pos
–
int
int
Returns the index of the format at position
pos
.
PySide2.QtGui.QAbstractTextDocumentLayout.
frameBoundingRect
(
frame
)
¶
frame
–
QTextFrame
QRectF
Returns the bounding rectangle of
frame
.
PySide2.QtGui.QAbstractTextDocumentLayout.
handlerForObject
(
objectType
)
¶
objectType
–
int
Returns a handler for objects of the given
objectType
.
PySide2.QtGui.QAbstractTextDocumentLayout.
hitTest
(
point
,
accuracy
)
¶
point
–
QPointF
accuracy
–
HitTestAccuracy
int
Returns the cursor position for the given
point
with the specified
accuracy
. Returns -1 if no valid cursor position was found.
PySide2.QtGui.QAbstractTextDocumentLayout.
imageAt
(
pos
)
¶
pos
–
QPointF
unicode
Returns the source of the image at the given position
pos
, or an empty string if no image exists at that point.
PySide2.QtGui.QAbstractTextDocumentLayout.
pageCount
(
)
¶
int
Returns the number of pages contained in the layout.
另请参阅
PySide2.QtGui.QAbstractTextDocumentLayout.
pageCountChanged
(
newPages
)
¶
newPages
–
int
PySide2.QtGui.QAbstractTextDocumentLayout.
paintDevice
(
)
¶
Returns the paint device used to render the document’s layout.
另请参阅
PySide2.QtGui.QAbstractTextDocumentLayout.
positionInlineObject
(
item
,
posInDocument
,
format
)
¶
item
–
QTextInlineObject
posInDocument
–
int
format
–
QTextFormat
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.
另请参阅
PySide2.QtGui.QAbstractTextDocumentLayout.
registerHandler
(
objectType
,
component
)
¶
objectType
–
int
component
–
QObject
Registers the given
component
as a handler for items of the given
objectType
.
注意
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
.
PySide2.QtGui.QAbstractTextDocumentLayout.
resizeInlineObject
(
item
,
posInDocument
,
format
)
¶
item
–
QTextInlineObject
posInDocument
–
int
format
–
QTextFormat
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.
PySide2.QtGui.QAbstractTextDocumentLayout.
setPaintDevice
(
device
)
¶
device
–
QPaintDevice
Sets the paint device used for rendering the document’s layout to the given
device
.
另请参阅
PySide2.QtGui.QAbstractTextDocumentLayout.
unregisterHandler
(
objectType
[
,
component=None
]
)
¶
objectType
–
int
component
–
QObject
Unregisters the given
component
as a handler for items of the given
objectType
, or any handler if the
component
is not specified.
PySide2.QtGui.QAbstractTextDocumentLayout.
update
(
[
arg__1=QRectF(0.
,
0.
,
1000000000.
,
1000000000.)
]
)
¶
arg__1
–
QRectF
PySide2.QtGui.QAbstractTextDocumentLayout.
updateBlock
(
block
)
¶
block
–
QTextBlock