QwtText(3) A class representing a text.


#include <qwt_text.h>

Public Types

enum LayoutAttribute { MinimumLayout = 1 }

enum PaintAttribute { PaintUsingTextFont = 1, PaintUsingTextColor = 2, PaintBackground = 4 }

enum TextFormat { AutoText = 0, PlainText, RichText, MathMLText, TeXText, OtherFormat = 100 }

Public Member Functions

QBrush backgroundBrush () const

QPen backgroundPen () const

QColor color () const

void draw (QPainter *painter, const QRect &rect) const

QFont font () const

int heightForWidth (int width, const QFont &=QFont()) const

bool isEmpty () const

bool isNull () const

int operator!= (const QwtText &) const

QwtText & operator= (const QwtText &)

int operator== (const QwtText &) const

QwtText (const QwtText &)

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

int renderFlags () const

void setBackgroundBrush (const QBrush &)

void setBackgroundPen (const QPen &)

void setColor (const QColor &)

void setFont (const QFont &)

void setLayoutAttribute (LayoutAttribute, bool on=true)

void setPaintAttribute (PaintAttribute, bool on=true)

void setRenderFlags (int flags)

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

bool testLayoutAttribute (LayoutAttribute) const

bool testPaintAttribute (PaintAttribute) const

QString text () const

QSize textSize (const QFont &=QFont()) const

QColor usedColor (const QColor &) const

QFont usedFont (const QFont &) const

~QwtText ()

Static Public Member Functions

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

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

static const QwtTextEngine * textEngine (QwtText::TextFormat)

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 QwtTextEngine for this format.
  • Background

     A text might have a background, defined by a QPen and QBrush to improve its visibility.
  • 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

Member Enumeration Documentation

enum QwtText::LayoutAttribute

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

  • 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. 

enum QwtText::PaintAttribute

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

  • PaintUsingTextFont

     The text has an individual font.
  • PaintUsingTextColor

     The text has an individual color.
  • PaintBackground

     The text has an individual background. 

enum QwtText::TextFormat

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

  • 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 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. The Qwt MathML extension offers such an engine based on the MathML renderer of the Qt solutions package. Unfortunately it is only available for owners of a commercial Qt license.
  • TeXText

     Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine to display the text.
  • OtherFormat

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

See also:

QwtTextEngine, setTextEngine()

Constructor & Destructor Documentation

QwtText::QwtText (const QString &text = QString::null, QwtText::TextFormattextFormat = AutoText)Constructor


text Text content
textFormat Text format

QwtText::QwtText (const QwtText &other)

Copy constructor.

QwtText::~QwtText ()


Member Function Documentation

QBrush QwtText::backgroundBrush () constReturns:

Background brush

See also:

setBackgroundBrush(), backgroundPen()

QPen QwtText::backgroundPen () constReturns:

Background pen

See also:

setBackgroundPen(), backgroundBrush()

QColor QwtText::color () const

Return the pen color, used for painting the text.

void QwtText::draw (QPainter *painter, const QRect &rect) constDraw a text into a rectangle


painter Painter
rect Rectangle

QFont QwtText::font () const

Return the font.

int QwtText::heightForWidth (intwidth, const QFont &defaultFont = QFont()) constFind the height for a given width


defaultFont Font, used for the calculation if the text has no font
width Width


Calculated height

bool QwtText::isEmpty () const [inline]Returns:


bool QwtText::isNull () const [inline]Returns:


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

Relational operator.

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

Assignment operator.

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

Relational operator.

int QwtText::renderFlags () constReturns:

Render flags

See also:


void QwtText::setBackgroundBrush (const QBrush &brush)Set the background brush


brush Background brush

See also:

backgroundBrush(), setBackgroundPen()

void QwtText::setBackgroundPen (const QPen &pen)Set the background pen


pen Background pen

See also:

backgroundPen(), setBackgroundBrush()

void QwtText::setColor (const QColor &color)Set the pen color used for painting the text.


color Color


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

void QwtText::setFont (const QFont &font)Set the font.


font Font


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

void QwtText::setLayoutAttribute (LayoutAttributeattribute, boolon = true)Change a layout attribute


attribute Layout attribute
on On/Off

See also:


void QwtText::setPaintAttribute (PaintAttributeattribute, boolon = true)Change a paint attribute


attribute Paint attribute
on On/Off


Used by setFont(), setColor(), setBackgroundPen() and setBackgroundBrush()

See also:


void QwtText::setRenderFlags (intrenderFlags)

Change the render flags. The default setting is Qt::AlignCenter


renderFlags Bitwise OR of the flags used like in QPainter::drawText

See also:

renderFlags(), QwtTextEngine::draw()


Some renderFlags might have no effect, depending on the text format.

void QwtText::setText (const QString &text, QwtText::TextFormattextFormat = AutoText)Assign a new text content


text Text content
textFormat Text format

See also:


void QwtText::setTextEngine (QwtText::TextFormatformat, 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.

Owner of a commercial Qt license can build the qwtmathml library, that is based on the MathML renderer, that is included in MML Widget component of the Qt solutions package.

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


format Text format
engine Text engine

See also:



Using QwtText::AutoText does nothing.

bool QwtText::testLayoutAttribute (LayoutAttributeattribute) constTest a layout attribute


attribute Layout attribute


true, if attribute is enabled

See also:


bool QwtText::testPaintAttribute (PaintAttributeattribute) constTest a paint attribute


attribute Paint attribute


true, if attribute is enabled

See also:


QString QwtText::text () constReturn the text.

See also:


const QwtTextEngine * QwtText::textEngine (QwtText::TextFormatformat) [static]

Find the text engine for a text format. textEngine can be used to find out if a text format is supported. F.e, if one wants to use MathML labels, the MathML renderer from the commercial Qt solutions package might be required, that is not available in Qt Open Source Edition environments.


format Text format


The text engine, or NULL if no engine is available.

const QwtTextEngine * QwtText::textEngine (const QString &text, QwtText::TextFormatformat = 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 returnd.

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


text Text, needed in case of AutoText
format Text format

QSize QwtText::textSize (const QFont &defaultFont = QFont()) constFind the height for a given width


defaultFont Font, used for the calculation if the text has no font


Calculated height

Returns the size, that is needed to render text


defaultFont Font of the text


Caluclated size

QColor QwtText::usedColor (const QColor &defaultColor) constReturn the color of the text, if it has one. Otherwise return defaultColor.


defaultColor Default color

See also:

setColor(), color(), PaintAttributes

QFont QwtText::usedFont (const QFont &defaultFont) constReturn the font of the text, if it has one. Otherwise return defaultFont.


defaultFont Default font

See also:

setFont(), font(), PaintAttributes


Generated automatically by Doxygen for Qwt User's Guide from the source code.