QGraphicsSimpleTextItem Class
The QGraphicsSimpleTextItem class provides a simple text path item that you can add to a QGraphicsScene. More...
Header: | #include <QGraphicsSimpleTextItem> |
qmake: | QT += widgets |
Since: | Qt 4.2 |
Inherits: | QAbstractGraphicsShapeItem |
Public Types
enum | anonymous { Type } |
Public Functions
QGraphicsSimpleTextItem(QGraphicsItem *parent = nullptr) | |
QGraphicsSimpleTextItem(const QString &text, QGraphicsItem *parent = nullptr) | |
virtual | ~QGraphicsSimpleTextItem() |
QFont | font() const |
void | setFont(const QFont &font) |
void | setText(const QString &text) |
QString | text() const |
Reimplemented Public Functions
virtual QRectF | boundingRect() const override |
virtual bool | contains(const QPointF &point) const override |
virtual bool | isObscuredBy(const QGraphicsItem *item) const override |
virtual QPainterPath | opaqueArea() const override |
virtual void | paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override |
virtual QPainterPath | shape() const override |
virtual int | type() const override |
- 6 public functions inherited from QAbstractGraphicsShapeItem
- 176 public functions inherited from QGraphicsItem
Additional Inherited Members
- 24 protected functions inherited from QGraphicsItem
Detailed Description
The QGraphicsSimpleTextItem class provides a simple text path item that you can add to a QGraphicsScene.
To set the item's text, you can either pass a QString to QGraphicsSimpleTextItem's constructor, or call setText() to change the text later. To set the text fill color, call setBrush().
The simple text item can have both a fill and an outline; setBrush() will set the text fill (i.e., text color), and setPen() sets the pen that will be used to draw the text outline. (The latter can be slow, especially for complex pens, and items with long text content.) If all you want is to draw a simple line of text, you should call setBrush() only, and leave the pen unset; QGraphicsSimpleTextItem's pen is by default Qt::NoPen.
QGraphicsSimpleTextItem uses the text's formatted size and the associated font to provide a reasonable implementation of boundingRect(), shape(), and contains(). You can set the font by calling setFont().
QGraphicsSimpleText does not display rich text; instead, you can use QGraphicsTextItem, which provides full text control capabilities.
See also QGraphicsTextItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPixmapItem, QGraphicsPolygonItem, QGraphicsLineItem, and Graphics View Framework.
Member Type Documentation
enum QGraphicsSimpleTextItem::anonymous
The value returned by the virtual type() function.
Constant | Value | Description |
---|---|---|
QGraphicsSimpleTextItem::Type |
9 |
A graphics simple text item |
Member Function Documentation
QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(QGraphicsItem *parent = nullptr)
Constructs a QGraphicsSimpleTextItem.
parent is passed to QGraphicsItem's constructor.
See also QGraphicsScene::addItem().
QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(const QString &text, QGraphicsItem *parent = nullptr)
Constructs a QGraphicsSimpleTextItem, using text as the default plain text.
parent is passed to QGraphicsItem's constructor.
See also QGraphicsScene::addItem().
[virtual]
QGraphicsSimpleTextItem::~QGraphicsSimpleTextItem()
Destroys the QGraphicsSimpleTextItem.
[override virtual]
QRectF QGraphicsSimpleTextItem::boundingRect() const
Reimplemented from QGraphicsItem::boundingRect().
[override virtual]
bool QGraphicsSimpleTextItem::contains(const QPointF &point) const
Reimplemented from QGraphicsItem::contains().
QFont QGraphicsSimpleTextItem::font() const
Returns the font that is used to draw the item's text.
See also setFont().
[override virtual]
bool QGraphicsSimpleTextItem::isObscuredBy(const QGraphicsItem *item) const
Reimplemented from QAbstractGraphicsShapeItem::isObscuredBy().
[override virtual]
QPainterPath QGraphicsSimpleTextItem::opaqueArea() const
Reimplemented from QAbstractGraphicsShapeItem::opaqueArea().
[override virtual]
void QGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Reimplemented from QGraphicsItem::paint().
void QGraphicsSimpleTextItem::setFont(const QFont &font)
Sets the font that is used to draw the item's text to font.
See also font().
void QGraphicsSimpleTextItem::setText(const QString &text)
Sets the item's text to text. The text will be displayed as plain text. Newline characters ('\n') as well as characters of type QChar::LineSeparator will cause item to break the text into multiple lines.
See also text().
[override virtual]
QPainterPath QGraphicsSimpleTextItem::shape() const
Reimplemented from QGraphicsItem::shape().
QString QGraphicsSimpleTextItem::text() const
Returns the item's text.
See also setText().
[override virtual]
int QGraphicsSimpleTextItem::type() const
Reimplemented from QGraphicsItem::type().
© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-5.12/qgraphicssimpletextitem.html