OGS
QNonScalableGraphicsTextItem.cpp
Go to the documentation of this file.
1 
16 
17 #include <QPainter>
18 
21  QGraphicsItem* parent)
22  : QGraphicsTextItem(parent)
23 {
24  setAcceptDrops(true);
25  setAcceptHoverEvents(true);
26  setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
27 }
28 
31  const QString& text, QGraphicsItem* parent)
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 }
42 
44 
46 void QNonScalableGraphicsTextItem::paint(QPainter* painter,
47  const QStyleOptionGraphicsItem* option,
48  QWidget* widget)
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 }
55 
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 }
Definition of the QNonScalableGraphicsTextItem class.
QRectF boundingRect() const override
Returns the bounding rectangle of the text item.
QNonScalableGraphicsTextItem(QGraphicsItem *parent=nullptr)
Constructor using a QGraphicsTextItem.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Paints the text item.
~QNonScalableGraphicsTextItem() override