Struct qt_gui::QStaticText
source · #[repr(C)]pub struct QStaticText { /* private fields */ }
Expand description
The QStaticText class enables optimized drawing of text when the text and its layout is updated rarely.
C++ class: QStaticText
.
The QStaticText class enables optimized drawing of text when the text and its layout is updated rarely.
QStaticText provides a way to cache layout data for a block of text so that it can be drawn more efficiently than by using QPainter::drawText() 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, QPainter::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; };
The QStaticText class can be used to mimic the behavior of QPainter::drawText() to a specific point with no boundaries, and also when QPainter::drawText() is called with a bounding rectangle.
If a bounding rectangle is not required, create a QStaticText object without setting a preferred text width. The text will then occupy a single line.
If you set a text width on the QStaticText object, this will bound the text. The text will be formatted so that no line exceeds the given width. The text width set for QStaticText will not automatically be used for clipping. To achieve clipping in addition to line breaks, use QPainter::setClipRect(). The position of the text is decided by the argument passed to QPainter::drawStaticText() 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. QStaticText will attempt to guess the format of the input text using Qt::mightBeRichText(), and interpret it as rich text if this function returns true
. To force QStaticText to display its contents as either plain text or rich text, use the function QStaticText::setTextFormat() and pass in, respectively, Qt::PlainText and Qt::RichText.
QStaticText can 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 QPainter::drawStaticText() call where it occurs. To avoid this overhead in the paint event, you can call prepare() ahead of time to ensure that the layout is calculated.
Implementations§
source§impl QStaticText
impl QStaticText
sourcepub unsafe fn copy_from(
&self,
arg1: impl CastInto<Ref<QStaticText>>
) -> Ref<QStaticText>
pub unsafe fn copy_from( &self, arg1: impl CastInto<Ref<QStaticText>> ) -> Ref<QStaticText>
Assigns other to this QStaticText.
Calls C++ function: QStaticText& QStaticText::operator=(const QStaticText& arg1)
.
Assigns other to this QStaticText.
sourcepub unsafe fn new_0a() -> CppBox<QStaticText>
pub unsafe fn new_0a() -> CppBox<QStaticText>
Constructs an empty QStaticText
Calls C++ function: [constructor] void QStaticText::QStaticText()
.
Constructs an empty QStaticText
sourcepub unsafe fn new_1a(text: impl CastInto<Ref<QString>>) -> CppBox<QStaticText>
pub unsafe fn new_1a(text: impl CastInto<Ref<QString>>) -> CppBox<QStaticText>
Constructs a QStaticText object with the given text.
Calls C++ function: [constructor] void QStaticText::QStaticText(const QString& text)
.
Constructs a QStaticText object with the given text.
sourcepub unsafe fn new_copy(
other: impl CastInto<Ref<QStaticText>>
) -> CppBox<QStaticText>
pub unsafe fn new_copy( other: impl CastInto<Ref<QStaticText>> ) -> CppBox<QStaticText>
Constructs a QStaticText object which is a copy of other.
Calls C++ function: [constructor] void QStaticText::QStaticText(const QStaticText& other)
.
Constructs a QStaticText object which is a copy of other.
sourcepub unsafe fn performance_hint(&self) -> PerformanceHint
pub unsafe fn performance_hint(&self) -> PerformanceHint
Returns which performance hint is set for the QStaticText.
Calls C++ function: QStaticText::PerformanceHint QStaticText::performanceHint() const
.
Returns which performance hint is set for the QStaticText.
See also setPerformanceHint().
sourcepub unsafe fn prepare_2a(
&self,
matrix: impl CastInto<Ref<QTransform>>,
font: impl CastInto<Ref<QFont>>
)
pub unsafe fn prepare_2a( &self, matrix: impl CastInto<Ref<QTransform>>, font: impl CastInto<Ref<QFont>> )
Prepares the QStaticText object for being painted with the given matrix and the given font to avoid overhead when the actual drawStaticText() call is made.
Calls C++ function: void QStaticText::prepare(const QTransform& matrix = …, const QFont& font = …)
.
Prepares the QStaticText object for being painted with the given matrix and the given 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 prepare() function and pass in the matrix and font you expect to use when drawing the text.
See also QPainter::setFont() and QPainter::setMatrix().
sourcepub unsafe fn prepare_1a(&self, matrix: impl CastInto<Ref<QTransform>>)
pub unsafe fn prepare_1a(&self, matrix: impl CastInto<Ref<QTransform>>)
Prepares the QStaticText object for being painted with the given matrix and the given font to avoid overhead when the actual drawStaticText() call is made.
Calls C++ function: void QStaticText::prepare(const QTransform& matrix = …)
.
Prepares the QStaticText object for being painted with the given matrix and the given 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 prepare() function and pass in the matrix and font you expect to use when drawing the text.
See also QPainter::setFont() and QPainter::setMatrix().
sourcepub unsafe fn prepare_0a(&self)
pub unsafe fn prepare_0a(&self)
Prepares the QStaticText object for being painted with the given matrix and the given font to avoid overhead when the actual drawStaticText() call is made.
Calls C++ function: void QStaticText::prepare()
.
Prepares the QStaticText object for being painted with the given matrix and the given 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 prepare() function and pass in the matrix and font you expect to use when drawing the text.
See also QPainter::setFont() and QPainter::setMatrix().
sourcepub unsafe fn set_performance_hint(&self, performance_hint: PerformanceHint)
pub unsafe fn set_performance_hint(&self, performance_hint: 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.
Calls C++ function: void QStaticText::setPerformanceHint(QStaticText::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.
The default is QStaticText::ModerateCaching.
Note: This function will cause the layout of the text to require recalculation.
See also performanceHint().
sourcepub unsafe fn set_text(&self, text: impl CastInto<Ref<QString>>)
pub unsafe fn set_text(&self, text: impl CastInto<Ref<QString>>)
Sets the text of the QStaticText to text.
Calls C++ function: void QStaticText::setText(const QString& text)
.
Sets the text of the QStaticText to text.
Note: This function will cause the layout of the text to require recalculation.
See also text().
sourcepub unsafe fn set_text_format(&self, text_format: TextFormat)
pub unsafe fn set_text_format(&self, text_format: TextFormat)
Sets the text format of the QStaticText to textFormat. If textFormat is set to Qt::AutoText (the default), the format of the text will try to be determined using the function Qt::mightBeRichText(). If the text format is Qt::PlainText, then the text will be displayed as is, whereas it will be interpreted as HTML if the format is Qt::RichText. HTML tags that alter the font of the text, its color, or its layout are supported by QStaticText.
Calls C++ function: void QStaticText::setTextFormat(Qt::TextFormat textFormat)
.
Sets the text format of the QStaticText to textFormat. If textFormat is set to Qt::AutoText (the default), the format of the text will try to be determined using the function Qt::mightBeRichText(). If the text format is Qt::PlainText, then the text will be displayed as is, whereas it will be interpreted as HTML if the format is Qt::RichText. HTML tags that alter the font of the text, its color, or its layout are supported by QStaticText.
Note: This function will cause the layout of the text to require recalculation.
See also textFormat(), setText(), and text().
sourcepub unsafe fn set_text_option(
&self,
text_option: impl CastInto<Ref<QTextOption>>
)
pub unsafe fn set_text_option( &self, text_option: impl CastInto<Ref<QTextOption>> )
Sets the text option structure that controls the layout process to the given textOption.
Calls C++ function: void QStaticText::setTextOption(const QTextOption& textOption)
.
Sets the text option structure that controls the layout process to the given textOption.
See also textOption().
sourcepub unsafe fn set_text_width(&self, text_width: c_double)
pub unsafe fn set_text_width(&self, text_width: c_double)
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.
Calls C++ function: void QStaticText::setTextWidth(double textWidth)
.
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.
Use size() to get the actual size of the text.
Note: This function will cause the layout of the text to require recalculation.
sourcepub unsafe fn size(&self) -> CppBox<QSizeF>
pub unsafe fn size(&self) -> CppBox<QSizeF>
Returns the size of the bounding rect for this QStaticText.
Calls C++ function: QSizeF QStaticText::size() const
.
Returns the size of the bounding rect for this QStaticText.
See also textWidth().
sourcepub unsafe fn swap(&self, other: impl CastInto<Ref<QStaticText>>)
pub unsafe fn swap(&self, other: impl CastInto<Ref<QStaticText>>)
Swaps this static text instance with other. This function is very fast and never fails.
Calls C++ function: void QStaticText::swap(QStaticText& other)
.
Swaps this static text instance with other. This function is very fast and never fails.
This function was introduced in Qt 5.0.
sourcepub unsafe fn text(&self) -> CppBox<QString>
pub unsafe fn text(&self) -> CppBox<QString>
Returns the text of the QStaticText.
Calls C++ function: QString QStaticText::text() const
.
Returns the text of the QStaticText.
See also setText().
sourcepub unsafe fn text_format(&self) -> TextFormat
pub unsafe fn text_format(&self) -> TextFormat
Returns the text format of the QStaticText.
Calls C++ function: Qt::TextFormat QStaticText::textFormat() const
.
Returns the text format of the QStaticText.
See also setTextFormat(), setText(), and text().
sourcepub unsafe fn text_option(&self) -> CppBox<QTextOption>
pub unsafe fn text_option(&self) -> CppBox<QTextOption>
Returns the current text option used to control the layout process.
Calls C++ function: QTextOption QStaticText::textOption() const
.
Returns the current text option used to control the layout process.
See also setTextOption().
sourcepub unsafe fn text_width(&self) -> c_double
pub unsafe fn text_width(&self) -> c_double
Returns the preferred width for this QStaticText.
Calls C++ function: double QStaticText::textWidth() const
.
Returns the preferred width for this QStaticText.
See also setTextWidth().
Trait Implementations§
source§impl CppDeletable for QStaticText
impl CppDeletable for QStaticText
source§unsafe fn delete(&self)
unsafe fn delete(&self)
Destroys the QStaticText.
Calls C++ function: [destructor] void QStaticText::~QStaticText()
.
Destroys the QStaticText.
source§impl PartialEq<Ref<QStaticText>> for QStaticText
impl PartialEq<Ref<QStaticText>> for QStaticText
source§fn eq(&self, arg1: &Ref<QStaticText>) -> bool
fn eq(&self, arg1: &Ref<QStaticText>) -> bool
Compares other to this QStaticText. Returns true
if the texts, fonts and text widths are equal.
Calls C++ function: bool QStaticText::operator==(const QStaticText& arg1) const
.
Compares other to this QStaticText. Returns true
if the texts, fonts and text widths are equal.
source§impl Size for QStaticText
impl Size for QStaticText
source§unsafe fn size(&self) -> usize
unsafe fn size(&self) -> usize
Returns the size of the bounding rect for this QStaticText.
Calls C++ function: QSizeF QStaticText::size() const
.
Returns the size of the bounding rect for this QStaticText.
See also textWidth().