OGS
QNonScalableGraphicsTextItem.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <QPainter>
7
10 QGraphicsItem* parent)
11 : QGraphicsTextItem(parent)
12{
13 setAcceptDrops(true);
14 setAcceptHoverEvents(true);
15 setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
16}
17
20 const QString& text, QGraphicsItem* parent)
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}
31
33
36 const QStyleOptionGraphicsItem* option,
37 QWidget* widget)
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}
44
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}
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