QGraphicsTextItem Class
The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display formatted text. More...
| Header: | #include <QGraphicsTextItem> |
| qmake: | QT += widgets |
| Since: | Qt 4.2 |
| Inherits: | QGraphicsObject |
This class was introduced in Qt 4.2.
Public Types
| enum | anonymous { Type } |
Properties
- openExternalLinks : bool
- textCursor : QTextCursor
Public Functions
| bool | openExternalLinks() const |
| void | setOpenExternalLinks(bool open) |
| void | setTextCursor(const QTextCursor &cursor) |
| QTextCursor | textCursor() const |
Detailed Description
If you only need to show plain text in an item, consider using QGraphicsSimpleTextItem instead.
To set the item's text, pass a QString to QGraphicsTextItem's constructor, or call setHtml()/setPlainText().
QGraphicsTextItem 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().
It is possible to make the item editable by setting the Qt::TextEditorInteraction flag using setTextInteractionFlags().
The item's preferred text width can be set using setTextWidth() and obtained using textWidth().
Note: In order to align HTML text in the center, the item's text width must be set. Otherwise, you can call adjustSize() after setting the item's text.

Note: QGraphicsTextItem accepts hover events by default. You can change this with setAcceptHoverEvents().
See also QGraphicsSimpleTextItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPixmapItem, QGraphicsPolygonItem, QGraphicsLineItem, and Graphics View Framework.
Member Type Documentation
enum QGraphicsTextItem::anonymous
The value returned by the virtual type() function.
| Constant | Value | Description |
|---|---|---|
QGraphicsTextItem::Type | 8 | A graphics text item |
Property Documentation
openExternalLinks : bool
Specifies whether QGraphicsTextItem should automatically open links using QDesktopServices::openUrl() instead of emitting the linkActivated signal.
The default value is false.
Access functions:
| bool | openExternalLinks() const |
| void | setOpenExternalLinks(bool open) |
textCursor : QTextCursor
This property represents the visible text cursor in an editable text item.
By default, if the item's text has not been set, this property contains a null text cursor; otherwise it contains a text cursor placed at the start of the item's document.
Access functions:
| QTextCursor | textCursor() const |
| void | setTextCursor(const QTextCursor &cursor) |