QGraphicsSimpleTextItem 類

QGraphicsSimpleTextItem 類提供簡單文本路徑項,其可被添加到 QGraphicsScene . 更多...

頭: #include <QGraphicsSimpleTextItem>
qmake: QT += widgets
Since: Qt 4.2
繼承: QAbstractGraphicsShapeItem

該類在 Qt 4.2 引入。

公共類型

enum anonymous { Type }

公共函數

QGraphicsSimpleTextItem (const QString & text , QGraphicsItem * parent = nullptr)
QGraphicsSimpleTextItem (QGraphicsItem * parent = nullptr)
virtual ~QGraphicsSimpleTextItem ()
QFont font () const
void setFont (const QFont & font )
void setText (const QString & text )
QString text () const

重實現公共函數

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

詳細描述

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 (),和 contains (). You can set the font by calling setFont ().

QGraphicsSimpleText 不顯示富文本;相反,可使用 QGraphicsTextItem ,其提供完整文本控製能力。

另請參閱 QGraphicsTextItem , QGraphicsPathItem , QGraphicsRectItem , QGraphicsEllipseItem , QGraphicsPixmapItem , QGraphicsPolygonItem , QGraphicsLineItem ,和 圖形視圖框架 .

成員類型文檔編製

enum QGraphicsSimpleTextItem:: anonymous

值的返迴是通過虛擬 type () 函數。

常量 描述
QGraphicsSimpleTextItem::Type 9 A graphics simple text item

成員函數文檔編製

QGraphicsSimpleTextItem:: QGraphicsSimpleTextItem (const QString & text , QGraphicsItem * parent = nullptr)

構造 QGraphicsSimpleTextItem 使用 text 作為默認純文本。

parent 被傳遞給 QGraphicsItem 的構造函數。

另請參閱 QGraphicsScene::addItem ().

QGraphicsSimpleTextItem:: QGraphicsSimpleTextItem ( QGraphicsItem * parent = nullptr)

構造 QGraphicsSimpleTextItem。

parent 被傳遞給 QGraphicsItem 的構造函數。

另請參閱 QGraphicsScene::addItem ().

[虛擬] QGraphicsSimpleTextItem:: ~QGraphicsSimpleTextItem ()

銷毀 QGraphicsSimpleTextItem .

[override virtual] QRectF QGraphicsSimpleTextItem:: boundingRect () const

重實現: QGraphicsItem::boundingRect () const.

[override virtual] bool QGraphicsSimpleTextItem:: contains (const QPointF & point ) const

重實現: QGraphicsItem::contains (const QPointF &point) const.

QFont QGraphicsSimpleTextItem:: font () const

返迴用於繪製項文本的字體。

另請參閱 setFont ().

[override virtual] bool QGraphicsSimpleTextItem:: isObscuredBy (const QGraphicsItem * item ) const

重實現: QAbstractGraphicsShapeItem::isObscuredBy (const QGraphicsItem *item) const.

[override virtual] QPainterPath QGraphicsSimpleTextItem:: opaqueArea () const

重實現: QAbstractGraphicsShapeItem::opaqueArea () const.

[override virtual] void QGraphicsSimpleTextItem:: paint ( QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget )

重實現: QGraphicsItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget).

void QGraphicsSimpleTextItem:: setFont (const QFont & font )

Sets the font that is used to draw the item's text to font .

另請參閱 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.

另請參閱 text ().

[override virtual] QPainterPath QGraphicsSimpleTextItem:: shape () const

重實現: QGraphicsItem::shape () const.

QString QGraphicsSimpleTextItem:: text () const

返迴項的文本。

另請參閱 setText ().

[override virtual] int QGraphicsSimpleTextItem:: type () const

重實現: QGraphicsItem::type () const.