OGS
QNonScalableGraphicsTextItem Class Reference

Detailed Description

A QGraphicsTextItem that will ignore all geometric transformations.

A QGraphicsTextItem that will ignore all geometric transformations to the underlying QGraphicsView/QGraphicsScene (in particular, it will not be scaled).

Definition at line 13 of file QNonScalableGraphicsTextItem.h.

#include <QNonScalableGraphicsTextItem.h>

Inheritance diagram for QNonScalableGraphicsTextItem:
[legend]
Collaboration diagram for QNonScalableGraphicsTextItem:
[legend]

Public Member Functions

 QNonScalableGraphicsTextItem (QGraphicsItem *parent=nullptr)
 Constructor using a QGraphicsTextItem.
 QNonScalableGraphicsTextItem (const QString &text, QGraphicsItem *parent=nullptr)
 Constructor using a QString.
 ~QNonScalableGraphicsTextItem () override
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 Paints the text item.
QRectF boundingRect () const override
 Returns the bounding rectangle of the text item.

Constructor & Destructor Documentation

◆ QNonScalableGraphicsTextItem() [1/2]

QNonScalableGraphicsTextItem::QNonScalableGraphicsTextItem ( QGraphicsItem * parent = nullptr)
explicit

Constructor using a QGraphicsTextItem.

Definition at line 9 of file QNonScalableGraphicsTextItem.cpp.

11 : QGraphicsTextItem(parent)
12{
13 setAcceptDrops(true);
14 setAcceptHoverEvents(true);
15 setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
16}

◆ QNonScalableGraphicsTextItem() [2/2]

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

Constructor using a QString.

Definition at line 19 of file QNonScalableGraphicsTextItem.cpp.

21 : QGraphicsTextItem(parent)
22{
23 if (!text.isEmpty())
24 {
25 setPlainText(text);
26 }
27 setAcceptDrops(true);
28 setAcceptHoverEvents(true);
29 setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
30}

◆ ~QNonScalableGraphicsTextItem()

QNonScalableGraphicsTextItem::~QNonScalableGraphicsTextItem ( )
overridedefault

Member Function Documentation

◆ boundingRect()

QRectF QNonScalableGraphicsTextItem::boundingRect ( ) const
override

Returns the bounding rectangle of the text item.

Definition at line 46 of file QNonScalableGraphicsTextItem.cpp.

47{
48 QRectF rect = QGraphicsTextItem::boundingRect();
49 return rect; // QRectF(rect.x()-rect.width()/2,
50 // rect.y()-rect.height()/2,rect.width(), rect.height());
51}

Referenced by StratScene::StratScene(), and paint().

◆ paint()

void QNonScalableGraphicsTextItem::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget )
override

Paints the text item.

Definition at line 35 of file QNonScalableGraphicsTextItem.cpp.

38{
39 // painter->drawRect(boundingRect());
40 QRectF rect = boundingRect();
41 painter->translate(-rect.width() / 2, -rect.height() / 2);
42 QGraphicsTextItem::paint(painter, option, widget);
43}
QRectF boundingRect() const override
Returns the bounding rectangle of the text item.

References boundingRect().


The documentation for this class was generated from the following files: