QGraphicsSimpleTextItem 类提供简单文本路径项,其可被添加到 QGraphicsScene . 更多...
头: | #include <QGraphicsSimpleTextItem> |
CMake: |
find_package(Qt6 COMPONENTS Widgets REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
继承: | QAbstractGraphicsShapeItem |
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 ,和 图形视图框架 .
值的返回通过虚拟 type () 函数。
常量 | 值 | 描述 |
---|---|---|
QGraphicsSimpleTextItem::Type
|
9
|
A graphics simple text item |
构造 QGraphicsSimpleTextItem 使用 text 作为默认纯文本。
parent 会被传递给 QGraphicsItem 的构造函数。
另请参阅 QGraphicsScene::addItem ().
构造 QGraphicsSimpleTextItem。
parent 会被传递给 QGraphicsItem 的构造函数。
另请参阅 QGraphicsScene::addItem ().
[虚拟]
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.
返回用于绘制项文本的字体。
另请参阅 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).
Sets the font that is used to draw the item's text to font .
另请参阅 font ().
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.
返回项的文本。
另请参阅 setText ().
[override virtual]
int
QGraphicsSimpleTextItem::
type
() const
重实现: QGraphicsItem::type () const.