PDA

View Full Version : how to fix the string with in the bounderies of the bounding rect



PHANI
3rd February 2012, 04:08
hi i want got some small problem add some text to the scene.. I JUST reimplement the QGraphicstextitem and forcing the bounding rect but the text was not fiting fully within the bounding rect only small part is visibling ...i want to put the text exactly with in the boundaries of the bounding tect...can some one please tell me how to do this?




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

QRectF boundingRect() const;
void forcePos(qreal x1, qreal y1, qreal x2, qreal y2);
private:
QRectF forcedSize;
};


QRectF QGraphicsTextItemSized::boundingRect() const
{
return forcedSize;
}
void QGraphicsTextItemSized::forcePos(qreal x1, qreal y1, qreal x2, qreal y2)
{
forcedSize.setCoords(0,0,x2-x1,y2-y1);
setPos(x1,y1);
}


QString teststring = "Test \n (.Y.) \n Test";
QGraphicsTextItemSized* text = new QGraphicsTextItemSized();
scene->addItem(text);
text->setPlainText(teststring);
text->forcePos(5,30,115,115);
text->setTextInteractionFlags(Qt::TextEditorInteraction) ;