QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
Public Member Functions | List of all members
QgsTextFragment Class Reference

Stores a fragment of text along with formatting overrides to be used when rendering the fragment. More...

#include <qgstextfragment.h>

Public Member Functions

 QgsTextFragment (const QString &text=QString(), const QgsTextCharacterFormat &format=QgsTextCharacterFormat())
 Constructor for QgsTextFragment, with the specified text and optional character format.
 
 QgsTextFragment (const QTextFragment &fragment)
 Constructor for QgsTextFragment, based on the specified QTextFragment fragment.
 
void applyCapitalization (Qgis::Capitalization capitalization)
 Applies a capitalization style to the fragment's text.
 
const QgsTextCharacterFormatcharacterFormat () const
 Returns the character formatting for the fragment.
 
double horizontalAdvance (const QFont &font, const QgsRenderContext &context, bool fontHasBeenUpdatedForFragment=false, double scaleFactor=1.0) const
 Returns the horizontal advance associated with this fragment, when rendered using the specified base font within the specified render context.
 
bool isTab () const
 Returns true if the fragment consists of just a tab character.
 
bool isWhitespace () const
 Returns true if the fragment consists of just whitespace characters, and does not contain any content to render.
 
void setCharacterFormat (const QgsTextCharacterFormat &format)
 Sets the character format for the fragment.
 
void setText (const QString &text)
 Sets the text content of the fragment.
 
QString text () const
 Returns the text content of the fragment.
 

Detailed Description

Stores a fragment of text along with formatting overrides to be used when rendering the fragment.

Warning
This API is not considered stable and may change in future QGIS versions.
Since
QGIS 3.14

Definition at line 35 of file qgstextfragment.h.

Constructor & Destructor Documentation

◆ QgsTextFragment() [1/2]

QgsTextFragment::QgsTextFragment ( const QString &  text = QString(),
const QgsTextCharacterFormat format = QgsTextCharacterFormat() 
)
explicit

Constructor for QgsTextFragment, with the specified text and optional character format.

Definition at line 21 of file qgstextfragment.cpp.

◆ QgsTextFragment() [2/2]

QgsTextFragment::QgsTextFragment ( const QTextFragment &  fragment)
explicit

Constructor for QgsTextFragment, based on the specified QTextFragment fragment.

Definition at line 26 of file qgstextfragment.cpp.

Member Function Documentation

◆ applyCapitalization()

void QgsTextFragment::applyCapitalization ( Qgis::Capitalization  capitalization)

Applies a capitalization style to the fragment's text.

Since
QGIS 3.16

Definition at line 64 of file qgstextfragment.cpp.

◆ characterFormat()

const QgsTextCharacterFormat & QgsTextFragment::characterFormat ( ) const
inline

Returns the character formatting for the fragment.

See also
setCharacterFormat()

Definition at line 83 of file qgstextfragment.h.

◆ horizontalAdvance()

double QgsTextFragment::horizontalAdvance ( const QFont &  font,
const QgsRenderContext context,
bool  fontHasBeenUpdatedForFragment = false,
double  scaleFactor = 1.0 
) const

Returns the horizontal advance associated with this fragment, when rendered using the specified base font within the specified render context.

Set fontHasBeenUpdatedForFragment to true if font already represents the character format for this fragment.

The optional scaleFactor parameter can specify a font size scaling factor. It is recommended to set this to QgsTextRenderer::FONT_WORKAROUND_SCALE and then manually calculations based on the resultant font metrics. Failure to do so will result in poor quality text rendering at small font sizes.

Definition at line 48 of file qgstextfragment.cpp.

◆ isTab()

bool QgsTextFragment::isTab ( ) const
inline

Returns true if the fragment consists of just a tab character.

Since
QGIS 3.38

Definition at line 68 of file qgstextfragment.h.

◆ isWhitespace()

bool QgsTextFragment::isWhitespace ( ) const
inline

Returns true if the fragment consists of just whitespace characters, and does not contain any content to render.

Since
QGIS 3.38

Definition at line 76 of file qgstextfragment.h.

◆ setCharacterFormat()

void QgsTextFragment::setCharacterFormat ( const QgsTextCharacterFormat format)

Sets the character format for the fragment.

See also
characterFormat()

Definition at line 43 of file qgstextfragment.cpp.

◆ setText()

void QgsTextFragment::setText ( const QString &  text)

Sets the text content of the fragment.

See also
text()

Definition at line 38 of file qgstextfragment.cpp.

◆ text()

QString QgsTextFragment::text ( ) const

Returns the text content of the fragment.

See also
setText()

Definition at line 33 of file qgstextfragment.cpp.


The documentation for this class was generated from the following files: