qtqgraphicstextitem

QGraphicsTextItem inheritance. Strange behaviour


I created a class, inherited from QGraphicsTextItem. Object of this class must be movable and must send signal when MouseButton is up.

class MyTextItem: public QObject, public QGraphicsTextItem
{
    Q_OBJECT
public:
    MyTextItem(QObject* Object, QString str1): QGraphicsTextItem(str1), mRef(Object){}
    virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent* event);
    QObject* mRef;
signals:
    void sendSignal(int x, int y);

Then I create object:

MyTextItem* label = new MyTextItem(NULL, "QwertyuiopAsdfghjkl");
label->setPos(p);
label->setFlag(QGraphicsItem::ItemIsMovable, true);

And all is OK. But, when I add:

QFont f;
f.setBold(false);
f.setItalic(false);
f.setPixelSize(16);
f.setFamily("Arial");
f.setLetterSpacing(QFont::AbsoluteSpacing, 0.1);
label->setFont(f);
//
scene()->addItem(label);

My test became cutted off (font is bigger, but width of object is without changes)! Why?. When I use QGraphicsTextItem instead of MyTextItem all is fine.

How to update item size after font increasing?
Thank you!

enter image description here enter image description here


Solution

  • Wow! A wrote

    class PolygonLabel: public QGraphicsTextItem, public QObject
    

    instead of

    class PolygonLabel: public QObject, public QGraphicsTextItem
    

    and problem was done!