Text widgets — PythonQwt 0.14 Manual (original) (raw)

QwtText

class qwt.text.QwtText(text=None, textFormat=None, other=None)[source]

A class representing a text

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

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.

A text might have a background, defined by a QPen and QBrushto improve its visibility. The corners of the background might be rounded.

A text might have an individual font.

A text might have an individual color.

Flags from Qt.AlignmentFlag and Qt.TextFlag used like inQPainter.drawText().

..seealso:

:py:meth:qwt.text.QwtTextEngine, :py:meth:qwt.text.QwtTextLabel

Text formats:

Paint attributes:

Layout attributes:

class QwtText([_text=None_][, _textFormat=None_][, _other=None_])

Parameters:

classmethod make(text=None, textformat=None, renderflags=None, font=None, family=None, pointsize=None, weight=None, color=None, borderradius=None, borderpen=None, brush=None)[source]

Create and setup a new QwtText object (convenience function).

Parameters:

isEmpty()[source]

Returns:

True if text is empty

setText(text, textFormat=None)[source]

Assign a new text content

Parameters:

text()[source]

Returns:

Text content

setRenderFlags(renderFlags)[source]

Change the render flags

The default setting is Qt.AlignCenter

Parameters:

renderFlags (int) – Bitwise OR of the flags used like in QPainter.drawText()

renderFlags()[source]

Returns:

Render flags

See also

setRenderFlags()

setFont(font)[source]

Set the font.

Parameters:

font (QFont) – Font

Note

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

See also

font(), usedFont()

font()[source]

Returns:

Return the font

See also

setFont(), usedFont()

usedFont(defaultFont)[source]

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

Parameters:

defaultFont (QFont) – Default font

Returns:

Font used for drawing the text

See also

setFont(), font()

setColor(color)[source]

Set the pen color used for drawing the text.

Parameters:

color (QColor) – Color

Note

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

See also

color(), usedColor()

color()[source]

Returns:

Return the pen color, used for painting the text

See also

setColor(), usedColor()

usedColor(defaultColor)[source]

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

Parameters:

defaultColor (QColor) – Default color

Returns:

Color used for drawing the text

See also

setColor(), color()

setBorderRadius(radius)[source]

Set the radius for the corners of the border frame

Parameters:

radius (float) – Radius of a rounded corner

borderRadius()[source]

Returns:

Radius for the corners of the border frame

setBorderPen(pen)[source]

Set the background pen

Parameters:

pen (QPen) – Background pen

borderPen()[source]

Returns:

Background pen

setBackgroundBrush(brush)[source]

Set the background brush

Parameters:

brush (QBrush) – Background brush

backgroundBrush()[source]

Returns:

Background brush

setPaintAttribute(attribute, on=True)[source]

Change a paint attribute

Parameters:

Note

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

testPaintAttribute(attribute)[source]

Test a paint attribute

Parameters:

attribute (int) – Paint attribute

Returns:

True, if attribute is enabled

setLayoutAttribute(attribute, on=True)[source]

Change a layout attribute

Parameters:

testLayoutAttribute(attribute)[source]

Test a layout attribute

Parameters:

attribute (int) – Layout attribute

Returns:

True, if attribute is enabled

heightForWidth(width, defaultFont=None)[source]

Find the height for a given width

Parameters:

Returns:

Calculated height

textSize(defaultFont)[source]

Returns the size, that is needed to render text

:param QFont defaultFont Font, used for the calculation if the text has no font :return: Caluclated size

draw(painter, rect)[source]

Draw a text into a rectangle

Parameters:

textEngine(text=None, format_=None)[source]

Find the text engine for a text format

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

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

Parameters:

Returns:

Corresponding text engine

setTextEngine(format_, engine)[source]

Assign/Replace a text engine for a text format

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

For QwtText.PlainText it is not allowed to assign a engine to None.

Parameters:

Warning

Using QwtText.AutoText does nothing.

QwtTextLabel

class qwt.text.QwtTextLabel(*args)[source]

A Widget which displays a QwtText

class QwtTextLabel(parent)

Parameters:

parent (QWidget) – Parent widget

class QwtTextLabel([_text=None_][, _parent=None_])

Parameters:

setPlainText(text)[source]

Interface for the designer plugin - does the same as setText()

Parameters:

text (str) – Text

plainText()[source]

Interface for the designer plugin

Returns:

Text as plain text

setText(text, textFormat=0)[source]

Change the label’s text, keeping all other QwtText attributes

Parameters:

text()[source]

Returns:

Return the text

clear()[source]

Clear the text and all QwtText attributes

indent()[source]

Returns:

Label’s text indent in pixels

setIndent(indent)[source]

Set label’s text indent in pixels

Parameters:

indent (int) – Indentation in pixels

margin()[source]

Returns:

Label’s text indent in pixels

setMargin(margin)[source]

Set label’s margin in pixels

Parameters:

margin (int) – Margin in pixels

sizeHint()[source]

Return a size hint

minimumSizeHint()[source]

Return a minimum size hint

heightForWidth(width)[source]

Parameters:

width (int) – Width

Returns:

Preferred height for this widget, given the width.

paintEvent(self, a0: QPaintEvent | None)[source]

drawContents(painter)[source]

Redraw the text and focus indicator

Parameters:

painter (QPainter) – Painter

drawText(painter, textRect)[source]

Redraw the text

Parameters:

textRect()[source]

Calculate geometry for the text in widget coordinates

Returns:

Geometry for the text

Text engines

QwtTextEngine

class qwt.text.QwtTextEngine[source]

Abstract base class for rendering text strings

A text engine is responsible for rendering texts for a specific text format. They are used by QwtText to render a text.

QwtPlainTextEngine and QwtRichTextEngine are part of thePythonQwt library.

heightForWidth(font, flags, text, width)[source]

Find the height for a given width

Parameters:

Returns:

Calculated height

textSize(font, flags, text)[source]

Returns the size, that is needed to render text

Parameters:

Returns:

Calculated size

mightRender(text)[source]

Test if a string can be rendered by this text engine

Parameters:

text (str) – Text to be tested

Returns:

True, if it can be rendered

textMargins(font)[source]

Return margins around the texts

The textSize might include margins around the text, like QFontMetrics::descent(). In situations where texts need to be aligned in detail, knowing these margins might improve the layout calculations.

Parameters:

font (QFont) – Font of the text

Returns:

tuple (left, right, top, bottom) representing margins

draw(painter, rect, flags, text)[source]

Draw the text in a clipping rectangle

Parameters:

QwtPlainTextEngine

class qwt.text.QwtPlainTextEngine[source]

A text engine for plain texts

QwtPlainTextEngine renders texts using the basic Qt classesQPainter and QFontMetrics.

heightForWidth(font, flags, text, width)[source]

Find the height for a given width

Parameters:

Returns:

Calculated height

textSize(font, flags, text)[source]

Returns the size, that is needed to render text

Parameters:

Returns:

Calculated size

textMargins(font)[source]

Return margins around the texts

The textSize might include margins around the text, like QFontMetrics::descent(). In situations where texts need to be aligned in detail, knowing these margins might improve the layout calculations.

Parameters:

font (QFont) – Font of the text

Returns:

tuple (left, right, top, bottom) representing margins

draw(painter, rect, flags, text)[source]

Draw the text in a clipping rectangle

Parameters:

mightRender(text)[source]

Test if a string can be rendered by this text engine

Parameters:

text (str) – Text to be tested

Returns:

True, if it can be rendered

QwtRichTextEngine

class qwt.text.QwtRichTextEngine[source]

A text engine for Qt rich texts

QwtRichTextEngine renders Qt rich texts using the classes of the Scribe framework of Qt.

heightForWidth(font, flags, text, width)[source]

Find the height for a given width

Parameters:

Returns:

Calculated height

textSize(font, flags, text)[source]

Returns the size, that is needed to render text

Parameters:

Returns:

Calculated size

draw(painter, rect, flags, text)[source]

Draw the text in a clipping rectangle

Parameters:

mightRender(text)[source]

Test if a string can be rendered by this text engine

Parameters:

text (str) – Text to be tested

Returns:

True, if it can be rendered

textMargins(font)[source]

Return margins around the texts

The textSize might include margins around the text, like QFontMetrics::descent(). In situations where texts need to be aligned in detail, knowing these margins might improve the layout calculations.

Parameters:

font (QFont) – Font of the text

Returns:

tuple (left, right, top, bottom) representing margins