PDA

View Full Version : Writing Text on a Rectangle!!!



Kapil
17th May 2006, 06:00
Hi..

i would like to write text inside a rectangle created using Q3CanvasRectangle, like some name of it and the coordinates for it.. how do i do that...
Plz help me in this..

Thanking you a lot...

with regards,
Kapil

munna
17th May 2006, 06:04
I think you can reimplement drawShape and write your text.

Kapil
17th May 2006, 07:45
I think you can reimplement drawShape and write your text.

thanks for the reply..

what i have done is used the Q3CanvasText and written by specifying the position.. just the only problem which i am facing is that when i provide motion to the canvas or move it the text does not move...
so i have to like set on the move for the text also with it..
what i want is that when i move the rectangle, the text moves with it as if its painted on the rectangle only...

how to do it..

thanks,

with regards,
Kapil

wysota
17th May 2006, 11:23
You have already been given your answer -- subclass QCanvasRectangle and reimplement drawShape so that it paints your text in the rectangle:


void CanvasRectangleWithText::drawShape(QPainter &p){
QCanvasRectangle::drawShape(p); // this draws the rectangle
p.drawText(rect(), Qt::AlignCenter, "Some text");
}