Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
QwtText Class Reference

A class representing a text. More...

#include <qwt_text.h>

Public Types

enum  TextFormat {
  AutoText = 0 , PlainText , RichText , MathMLText ,
  TeXText , OtherFormat = 100
}
 Text format. More...
 
enum  PaintAttribute { PaintUsingTextFont = 0x01 , PaintUsingTextColor = 0x02 , PaintBackground = 0x04 }
 Paint Attributes. More...
 
enum  LayoutAttribute { MinimumLayout = 0x01 }
 Layout Attributes The layout attributes affects some aspects of the layout of the text. More...
 
typedef QFlags< PaintAttributePaintAttributes
 
typedef QFlags< LayoutAttributeLayoutAttributes
 

Public Member Functions

 QwtText ()
 
 QwtText (const QString &, TextFormat textFormat=AutoText)
 
 QwtText (const QwtText &)
 Copy constructor.
 
 ~QwtText ()
 Destructor.
 
QwtTextoperator= (const QwtText &)
 Assignment operator.
 
bool operator== (const QwtText &) const
 Relational operator.
 
bool operator!= (const QwtText &) const
 Relational operator.
 
void setText (const QString &, QwtText::TextFormat textFormat=AutoText)
 
QString text () const
 
bool isNull () const
 
bool isEmpty () const
 
void setFont (const QFont &)
 
QFont font () const
 Return the font.
 
QFont usedFont (const QFont &) const
 
void setRenderFlags (int)
 Change the render flags.
 
int renderFlags () const
 
void setColor (const QColor &)
 
QColor color () const
 Return the pen color, used for painting the text.
 
QColor usedColor (const QColor &) const
 
void setBorderRadius (double)
 
double borderRadius () const
 
void setBorderPen (const QPen &)
 
QPen borderPen () const
 
void setBackgroundBrush (const QBrush &)
 
QBrush backgroundBrush () const
 
void setPaintAttribute (PaintAttribute, bool on=true)
 
bool testPaintAttribute (PaintAttribute) const
 
void setLayoutAttribute (LayoutAttribute, bool on=true)
 
bool testLayoutAttribute (LayoutAttribute) const
 
double heightForWidth (double width) const
 
double heightForWidth (double width, const QFont &) const
 
QSizeF textSize () const
 
QSizeF textSize (const QFont &) const
 
void draw (QPainter *painter, const QRectF &rect) const
 

Static Public Member Functions

static const QwtTextEnginetextEngine (const QString &text, QwtText::TextFormat=AutoText)
 
static const QwtTextEnginetextEngine (QwtText::TextFormat)
 Find the text engine for a text format.
 
static void setTextEngine (QwtText::TextFormat, QwtTextEngine *)
 

Detailed Description

A class representing a text.

A QwtText is a text including a set of attributes how to render it.

  • Format
    A text might include control sequences (f.e tags) describing how to render it. Each format (f.e MathML, TeX, Qt Rich Text) has its own set of control sequences, that can be handles by a special QwtTextEngine for this format.
  • Background
    A text might have a background, defined by a QPen and QBrush to improve its visibility. The corners of the background might be rounded.
  • Font
    A text might have an individual font.
  • Color
    A text might have an individual color.
  • Render Flags
    Flags from Qt::AlignmentFlag and Qt::TextFlag used like in QPainter::drawText().
See also
QwtTextEngine, QwtTextLabel

Definition at line 51 of file qwt_text.h.

Member Typedef Documentation

◆ LayoutAttributes

An ORed combination of LayoutAttribute values.

Definition at line 143 of file qwt_text.h.

◆ PaintAttributes

An ORed combination of PaintAttribute values.

Definition at line 126 of file qwt_text.h.

Member Enumeration Documentation

◆ LayoutAttribute

Layout Attributes The layout attributes affects some aspects of the layout of the text.

Enumerator
MinimumLayout 

Layout the text without its margins. This mode is useful if a text needs to be aligned accurately, like the tick labels of a scale. If QwtTextEngine::textMargins is not implemented for the format of the text, MinimumLayout has no effect.

Definition at line 132 of file qwt_text.h.

◆ PaintAttribute

Paint Attributes.

Font and color and background are optional attributes of a QwtText. The paint attributes hold the information, if they are set.

Enumerator
PaintUsingTextFont 

The text has an individual font.

PaintUsingTextColor 

The text has an individual color.

PaintBackground 

The text has an individual background.

Definition at line 114 of file qwt_text.h.

◆ TextFormat

Text format.

The text format defines the QwtTextEngine, that is used to render the text.

See also
QwtTextEngine, setTextEngine()
Enumerator
AutoText 

The text format is determined using QwtTextEngine::mightRender() for all available text engines in increasing order > PlainText. If none of the text engines can render the text is rendered like QwtText::PlainText.

PlainText 

Draw the text as it is, using a QwtPlainTextEngine.

RichText 

Use the Scribe framework (Qt Rich Text) to render the text.

MathMLText 

Use a MathML (http://en.wikipedia.org/wiki/MathML) render engine to display the text. In earlier versions of Qwt such an engine was included - since Qwt 6.2 it can be found here: https://github.com/uwerat/qwt-mml-dev

To enable MathML support the following code needs to be added to the application:

QwtText::setTextEngine( QwtText::MathMLText, new QwtMathMLTextEngine() );
@ MathMLText
Definition qwt_text.h:93
static void setTextEngine(QwtText::TextFormat, QwtTextEngine *)
Definition qwt_text.cpp:713
TeXText 

Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine to display the text ( not implemented yet ).

OtherFormat 

The number of text formats can be extended using setTextEngine. Formats >= QwtText::OtherFormat are not used by Qwt.

Definition at line 64 of file qwt_text.h.

Constructor & Destructor Documentation

◆ QwtText() [1/3]

QwtText::QwtText ( )

Constructor

Definition at line 201 of file qwt_text.cpp.

◆ QwtText() [2/3]

QwtText::QwtText ( const QString & text,
QwtText::TextFormat textFormat = AutoText )

Constructor

Parameters
textText content
textFormatText format

Definition at line 215 of file qwt_text.cpp.

◆ QwtText() [3/3]

QwtText::QwtText ( const QwtText & other)

Copy constructor.

Definition at line 225 of file qwt_text.cpp.

◆ ~QwtText()

QwtText::~QwtText ( )

Destructor.

Definition at line 235 of file qwt_text.cpp.

Member Function Documentation

◆ backgroundBrush()

QBrush QwtText::backgroundBrush ( ) const
Returns
Background brush
See also
setBackgroundBrush(), borderPen()

Definition at line 451 of file qwt_text.cpp.

◆ borderPen()

QPen QwtText::borderPen ( ) const
Returns
Background pen
See also
setBorderPen(), backgroundBrush()

Definition at line 430 of file qwt_text.cpp.

◆ borderRadius()

double QwtText::borderRadius ( ) const
Returns
Radius for the corners of the border frame
See also
setBorderRadius(), borderPen(), backgroundBrush()

Definition at line 409 of file qwt_text.cpp.

◆ color()

QColor QwtText::color ( ) const

Return the pen color, used for painting the text.

Definition at line 372 of file qwt_text.cpp.

◆ draw()

void QwtText::draw ( QPainter * painter,
const QRectF & rect ) const

Draw a text into a rectangle

Parameters
painterPainter
rectRectangle

Definition at line 615 of file qwt_text.cpp.

◆ font()

QFont QwtText::font ( ) const

Return the font.

Definition at line 336 of file qwt_text.cpp.

◆ heightForWidth() [1/2]

double QwtText::heightForWidth ( double width) const

Find the height for a given width

Parameters
widthWidth
Returns
Calculated height

Definition at line 522 of file qwt_text.cpp.

◆ heightForWidth() [2/2]

double QwtText::heightForWidth ( double width,
const QFont & defaultFont ) const

Find the height for a given width

Parameters
defaultFontFont, used for the calculation if the text has no font
widthWidth
Returns
Calculated height

Definition at line 535 of file qwt_text.cpp.

◆ isEmpty()

bool QwtText::isEmpty ( ) const
Returns
text().isEmpty()

Definition at line 739 of file qwt_text.cpp.

◆ isNull()

bool QwtText::isNull ( ) const
Returns
text().isNull()

Definition at line 733 of file qwt_text.cpp.

◆ operator!=()

bool QwtText::operator!= ( const QwtText & other) const

Relational operator.

Definition at line 264 of file qwt_text.cpp.

◆ operator=()

QwtText & QwtText::operator= ( const QwtText & other)

Assignment operator.

Definition at line 242 of file qwt_text.cpp.

◆ operator==()

bool QwtText::operator== ( const QwtText & other) const

Relational operator.

Definition at line 250 of file qwt_text.cpp.

◆ renderFlags()

int QwtText::renderFlags ( ) const
Returns
Render flags
See also
setRenderFlags()

Definition at line 317 of file qwt_text.cpp.

◆ setBackgroundBrush()

void QwtText::setBackgroundBrush ( const QBrush & brush)

Set the background brush

Parameters
brushBackground brush
See also
backgroundBrush(), setBorderPen()

Definition at line 441 of file qwt_text.cpp.

◆ setBorderPen()

void QwtText::setBorderPen ( const QPen & pen)

Set the background pen

Parameters
penBackground pen
See also
borderPen(), setBackgroundBrush()

Definition at line 420 of file qwt_text.cpp.

◆ setBorderRadius()

void QwtText::setBorderRadius ( double radius)

Set the radius for the corners of the border frame

Parameters
radiusRadius of a rounded corner
See also
borderRadius(), setBorderPen(), setBackgroundBrush()

Definition at line 400 of file qwt_text.cpp.

◆ setColor()

void QwtText::setColor ( const QColor & color)

Set the pen color used for drawing the text.

Parameters
colorColor
Note
Setting the color might have no effect, when the text contains control sequences for setting colors.

Definition at line 365 of file qwt_text.cpp.

◆ setFont()

void QwtText::setFont ( const QFont & font)

Set the font.

Parameters
fontFont
Note
Setting the font might have no effect, when the text contains control sequences for setting fonts.

Definition at line 329 of file qwt_text.cpp.

◆ setLayoutAttribute()

void QwtText::setLayoutAttribute ( LayoutAttribute attribute,
bool on = true )

Change a layout attribute

Parameters
attributeLayout attribute
onOn/Off
See also
testLayoutAttribute()

Definition at line 494 of file qwt_text.cpp.

◆ setPaintAttribute()

void QwtText::setPaintAttribute ( PaintAttribute attribute,
bool on = true )

Change a paint attribute

Parameters
attributePaint attribute
onOn/Off
Note
Used by setFont(), setColor(), setBorderPen() and setBackgroundBrush()
See also
testPaintAttribute()

Definition at line 466 of file qwt_text.cpp.

◆ setRenderFlags()

void QwtText::setRenderFlags ( int renderFlags)

Change the render flags.

The default setting is Qt::AlignCenter

Parameters
renderFlagsBitwise OR of the flags used like in QPainter::drawText()
See also
renderFlags(), QwtTextEngine::draw()
Note
Some renderFlags might have no effect, depending on the text format.

Definition at line 304 of file qwt_text.cpp.

◆ setText()

void QwtText::setText ( const QString & text,
QwtText::TextFormat textFormat = AutoText )

Assign a new text content

Parameters
textText content
textFormatText format
See also
text()

Definition at line 277 of file qwt_text.cpp.

◆ setTextEngine()

void QwtText::setTextEngine ( QwtText::TextFormat format,
QwtTextEngine * engine )
static

Assign/Replace a text engine for a text format

With setTextEngine it is possible to extend Qwt with other types of text formats.

For QwtText::PlainText it is not allowed to assign a engine == NULL.

Parameters
formatText format
engineText engine
Warning
Using QwtText::AutoText does nothing.

Definition at line 713 of file qwt_text.cpp.

◆ testLayoutAttribute()

bool QwtText::testLayoutAttribute ( LayoutAttribute attribute) const

Test a layout attribute

Parameters
attributeLayout attribute
Returns
true, if attribute is enabled
See also
setLayoutAttribute()

Definition at line 510 of file qwt_text.cpp.

◆ testPaintAttribute()

bool QwtText::testPaintAttribute ( PaintAttribute attribute) const

Test a paint attribute

Parameters
attributePaint attribute
Returns
true, if attribute is enabled
See also
setPaintAttribute()

Definition at line 482 of file qwt_text.cpp.

◆ text()

QString QwtText::text ( ) const
Returns
Text as QString.
See also
setText()

Definition at line 289 of file qwt_text.cpp.

◆ textEngine() [1/2]

const QwtTextEngine * QwtText::textEngine ( const QString & text,
QwtText::TextFormat format = AutoText )
static

Find the text engine for a text format

In case of QwtText::AutoText the first text engine (beside QwtPlainTextEngine) is returned, where QwtTextEngine::mightRender returns true. If there is none QwtPlainTextEngine is returned.

If no text engine is registered for the format QwtPlainTextEngine is returned.

Parameters
textText, needed in case of AutoText
formatText format
Returns
Corresponding text engine

Definition at line 694 of file qwt_text.cpp.

◆ textEngine() [2/2]

const QwtTextEngine * QwtText::textEngine ( QwtText::TextFormat format)
static

Find the text engine for a text format.

textEngine can be used to find out if a text format is supported.

Parameters
formatText format
Returns
The text engine, or NULL if no engine is available.

Definition at line 727 of file qwt_text.cpp.

◆ textSize() [1/2]

QSizeF QwtText::textSize ( ) const

Returns the size, that is needed to render text

Returns
Calculated size

Definition at line 570 of file qwt_text.cpp.

◆ textSize() [2/2]

QSizeF QwtText::textSize ( const QFont & defaultFont) const

Returns the size, that is needed to render text

Parameters
defaultFontFont of the text
Returns
Calculated size

Definition at line 581 of file qwt_text.cpp.

◆ usedColor()

QColor QwtText::usedColor ( const QColor & defaultColor) const

Return the color of the text, if it has one. Otherwise return defaultColor.

Parameters
defaultColorDefault color
Returns
Color used for drawing the text
See also
setColor(), color(), PaintAttributes

Definition at line 386 of file qwt_text.cpp.

◆ usedFont()

QFont QwtText::usedFont ( const QFont & defaultFont) const

Return the font of the text, if it has one. Otherwise return defaultFont.

Parameters
defaultFontDefault font
Returns
Font used for drawing the text
See also
setFont(), font(), PaintAttributes

Definition at line 350 of file qwt_text.cpp.