QStaticTextclass enables optimized drawing of text when the text and its layout is updated rarely. 更多 …
def
__eq__
(arg__1)
def
__ne__
(arg__1)
def
performanceHint
()
def
prepare
([matrix=QTransform()[, font=QFont()]])
def
setPerformanceHint
(performanceHint)
def
setText
(text)
def
setTextFormat
(textFormat)
def
setTextOption
(textOption)
def
setTextWidth
(textWidth)
def
size
()
def
swap
(other)
def
text
()
def
textFormat
()
def
textOption
()
def
textWidth
()
QStaticTextprovides a way to cache layout data for a block of text so that it can be drawn more efficiently than by usingdrawText()in which the layout information is recalculated with every call.The class primarily provides an optimization for cases where the text, its font and the transformations on the painter are static over several paint events. If the text or its layout is changed for every iteration,
drawText()is the more efficient alternative, since the static text’s layout would have to be recalculated to take the new state into consideration.Translating the painter will not cause the layout of the text to be recalculated, but will cause a very small performance impact on drawStaticText(). Altering any other parts of the painter’s transformation or the painter’s font will cause the layout of the static text to be recalculated. This should be avoided as often as possible to maximize the performance benefit of using
QStaticText.In addition, only affine transformations are supported by drawStaticText(). Calling drawStaticText() on a projected painter will perform slightly worse than using the regular drawText() call, so this should be avoided.
class MyWidget: public QWidget { public: MyWidget(QWidget *parent = 0) : QWidget(parent), m_staticText("This is static text") protected: void paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawStaticText(0, 0, m_staticText); } private: QStaticText m_staticText; };
QStaticTextclass can be used to mimic the behavior ofdrawText()to a specific point with no boundaries, and also whendrawText()is called with a bounding rectangle.If a bounding rectangle is not required, create a
QStaticTextobject without setting a preferred text width. The text will then occupy a single line.If you set a text width on the
QStaticTextobject, this will bound the text. The text will be formatted so that no line exceeds the given width. The text width set forQStaticTextwill not automatically be used for clipping. To achieve clipping in addition to line breaks, usesetClipRect(). The position of the text is decided by the argument passed todrawStaticText()and can change from call to call with a minimal impact on performance.For extra convenience, it is possible to apply formatting to the text using the HTML subset supported by
QTextDocument.QStaticTextwill attempt to guess the format of the input text usingmightBeRichText(), and interpret it as rich text if this function returnstrue. To forceQStaticTextto display its contents as either plain text or rich text, use the functionsetTextFormat()and pass in, respectively,PlainTextandRichText.
QStaticTextcan only represent text, so only HTML tags which alter the layout or appearance of the text will be respected. Adding an image to the input HTML, for instance, will cause the image to be included as part of the layout, affecting the positions of the text glyphs, but it will not be displayed. The result will be an empty area the size of the image in the output. Similarly, using tables will cause the text to be laid out in table format, but the borders will not be drawn.If it’s the first time the static text is drawn, or if the static text, or the painter’s font has been altered since the last time it was drawn, the text’s layout has to be recalculated. On some paint engines, changing the matrix of the painter will also cause the layout to be recalculated. In particular, this will happen for any engine except for the OpenGL2 paint engine. Recalculating the layout will impose an overhead on the
drawStaticText()call where it occurs. To avoid this overhead in the paint event, you can callprepare()ahead of time to ensure that the layout is calculated.
QStaticText
¶
QStaticText(other)
QStaticText(text)
- param other
- param text
unicode
构造空
QStaticText
PySide2.QtGui.QStaticText.
PerformanceHint
¶
This enum the different performance hints that can be set on the
QStaticText
. These hints can be used to indicate that the
QStaticText
should use additional caches, if possible, to improve performance at the expense of memory. In particular, setting the performance hint on the
QStaticText
will improve performance when using the OpenGL graphics system or when drawing to a
QOpenGLWidget
.
|
常量 |
描述 |
|---|---|
|
QStaticText.ModerateCaching |
Do basic caching for high performance at a low memory cost. |
|
QStaticText.AggressiveCaching |
Use additional caching when available. This may improve performance at a higher memory cost. |
PySide2.QtGui.QStaticText.
__ne__
(
arg__1
)
¶
arg__1
–
QStaticText
bool
比较
other
到此
QStaticText
。返回
true
if the texts, fonts or maximum sizes are different.
PySide2.QtGui.QStaticText.
__eq__
(
arg__1
)
¶
arg__1
–
QStaticText
bool
比较
other
到此
QStaticText
。返回
true
if the texts, fonts and text widths are equal.
PySide2.QtGui.QStaticText.
performanceHint
(
)
¶
Returns which performance hint is set for the
QStaticText
.
另请参阅
PySide2.QtGui.QStaticText.
prepare
(
[
matrix=QTransform()
[
,
font=QFont()
]
]
)
¶
matrix
–
QTransform
font
–
QFont
Prepares the
QStaticText
object for being painted with the given
matrix
和给定
font
to avoid overhead when the actual drawStaticText() call is made.
When drawStaticText() is called, the layout of the
QStaticText
will be recalculated if any part of the
QStaticText
object has changed since the last time it was drawn. It will also be recalculated if the painter’s font is not the same as when the
QStaticText
was last drawn, or, on any other paint engine than the OpenGL2 engine, if the painter’s matrix has been altered since the static text was last drawn.
To avoid the overhead of creating the layout the first time you draw the
QStaticText
after making changes, you can use the function and pass in the
matrix
and
font
you expect to use when drawing the text.
另请参阅
PySide2.QtGui.QStaticText.
setPerformanceHint
(
performanceHint
)
¶
performanceHint
–
PerformanceHint
Sets the performance hint of the
QStaticText
according to the
performanceHint
provided. The
performanceHint
is used to customize how much caching is done internally to improve performance.
默认为
ModerateCaching
.
注意
This function will cause the layout of the text to require recalculation.
另请参阅
PySide2.QtGui.QStaticText.
setText
(
text
)
¶
text – unicode
Sets the text of the
QStaticText
to
text
.
注意
This function will cause the layout of the text to require recalculation.
另请参阅
PySide2.QtGui.QStaticText.
setTextFormat
(
textFormat
)
¶
textFormat
–
TextFormat
Sets the text format of the
QStaticText
to
textFormat
。若
textFormat
is set to
AutoText
(the default), the format of the text will try to be determined using the function
mightBeRichText()
. If the text format is
PlainText
, then the text will be displayed as is, whereas it will be interpreted as HTML if the format is
RichText
. HTML tags that alter the font of the text, its color, or its layout are supported by
QStaticText
.
注意
This function will cause the layout of the text to require recalculation.
另请参阅
PySide2.QtGui.QStaticText.
setTextOption
(
textOption
)
¶
textOption
–
QTextOption
Sets the text option structure that controls the layout process to the given
textOption
.
另请参阅
PySide2.QtGui.QStaticText.
setTextWidth
(
textWidth
)
¶
textWidth
–
qreal
Sets the preferred width for this
QStaticText
. If the text is wider than the specified width, it will be broken into multiple lines and grow vertically. If the text cannot be split into multiple lines, it will be larger than the specified
textWidth
.
Setting the preferred text width to a negative number will cause the text to be unbounded.
使用
size()
to get the actual size of the text.
注意
This function will cause the layout of the text to require recalculation.
另请参阅
PySide2.QtGui.QStaticText.
size
(
)
¶
QSizeF
Returns the size of the bounding rect for this
QStaticText
.
另请参阅
PySide2.QtGui.QStaticText.
swap
(
other
)
¶
other
–
QStaticText
Swaps this static text instance with
other
。此函数非常快,且从不失败。
PySide2.QtGui.QStaticText.
text
(
)
¶
unicode
Returns the text of the
QStaticText
.
另请参阅
PySide2.QtGui.QStaticText.
textFormat
(
)
¶
TextFormat
Returns the text format of the
QStaticText
.
PySide2.QtGui.QStaticText.
textOption
(
)
¶
Returns the current text option used to control the layout process.
另请参阅
PySide2.QtGui.QStaticText.
textWidth
(
)
¶
qreal
Returns the preferred width for this
QStaticText
.
另请参阅