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 24 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 20 of file QNonScalableGraphicsTextItem.cpp.

22 : QGraphicsTextItem(parent)
23{
24 setAcceptDrops(true);
25 setAcceptHoverEvents(true);
26 setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
27}

◆ QNonScalableGraphicsTextItem() [2/2]

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

Constructor using a QString.

Definition at line 30 of file QNonScalableGraphicsTextItem.cpp.

32 : QGraphicsTextItem(parent)
33{
34 if (!text.isEmpty())
35 {
36 setPlainText(text);
37 }
38 setAcceptDrops(true);
39 setAcceptHoverEvents(true);
40 setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
41}

◆ ~QNonScalableGraphicsTextItem()

QNonScalableGraphicsTextItem::~QNonScalableGraphicsTextItem ( )
overridedefault

Member Function Documentation

◆ boundingRect()

QRectF QNonScalableGraphicsTextItem::boundingRect ( ) const
override

Returns the bounding rectangle of the text item.

Definition at line 57 of file QNonScalableGraphicsTextItem.cpp.

58{
59 QRectF rect = QGraphicsTextItem::boundingRect();
60 return rect; // QRectF(rect.x()-rect.width()/2,
61 // rect.y()-rect.height()/2,rect.width(), rect.height());
62}

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

◆ paint()

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

Paints the text item.

Definition at line 46 of file QNonScalableGraphicsTextItem.cpp.

49{
50 // painter->drawRect(boundingRect());
51 QRectF rect = boundingRect();
52 painter->translate(-rect.width() / 2, -rect.height() / 2);
53 QGraphicsTextItem::paint(painter, option, widget);
54}
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: