Adjust the size of QGraphicstextItem



  • hi, some help me,how can we adjust the size of QGraphistextitem...i reimplemented the QGraphicsTextitem and when i adjusted the bounding rect size..full text is not visibling ...please tell me how to adjust the size of that text to fix in rectitem...



  • this is the code i tried

    @
    class GraphicsTextItemSized : public QGraphicsTextItem
    {
    public:
    GraphicsTextItemSized(QGraphicsItem* parent = 0);
    GraphicsTextItemSized(const QString& text, QGraphicsItem* parent = 0);

    QRectF boundingRect() const;
    QString str;
    QRectF adjustedrect;
    
     void forcedsize(qreal x1,qreal y1,qreal x2,qreal y2);
    

    };
    @

    @
    #include "graphicstextitemsized.h"
    #include <QtCore>
    #include <QtGui>
    #include <QGraphicsTextItem>

    GraphicsTextItemSized::GraphicsTextItemSized(const QString &text, QGraphicsItem *parent):QGraphicsTextItem(text,parent)
    {
    setPlainText( text);
    }
    QRectF GraphicsTextItemSized::boundingRect() const
    {
    return (adjustedrect);
    }

    void GraphicsTextItemSized::forcedsize(qreal x1,qreal y1,qreal x2,qreal y2)
    {
    adjustedrect.setCoords(0,0,x2-x1,y2-y1);
    }

    @
    @
    QGraphicsRectItem *rect = new QGraphicsRectItem(0,0,0,0);
    GraphicsTextItemSized *tes = new GraphicsTextItemSized(QString("vcc"),rect);
    tes->forcedsize(0,0,10,10);
    tes->setPos(10.0,10.0);
    scene->addItem(rect);
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.