PDA

View Full Version : AddText to QRect on QGraphicsView



mohini
11th February 2011, 06:32
I am trying to add text on different Qrects I have plotted on the QGraphicsScene (added to QGraphicsView).
I have enabled horizontal zooming of the scene on mousewheel motion. I could add the text to QGraphicsScene but, when I zoom the scene the Text also gets zoomed.
I want to keep the Text size as it is but the text should shift (along with corresponding QRect ) according to the zooming factor ...

I have attached 2 images here ....59205921



any suggestions ??

wysota
11th February 2011, 08:07
Set the ItemIgnoresTransformations flag for your text items.

mohini
15th February 2011, 06:22
thanx...
I have one more query...
As you know , I have put a text on each QRect..
now,what I want is - >
initially I want only some portion of text to be visible as the QRect is smaller in size..
On zooming horizontally , the text should get completed according to the size of QRect...
How can I get this ?
currently the text is going outside the QRect before zooming....
attaching screenshots ...
59525953

mohini
16th February 2011, 05:50
I could find one method to do this....
using QGraphicsTextItem::setTextWidth();
but the problem is, initially the text is broken into many line which I can't hide...
so the broken text lines show up below the corresponding QRect....


attaching screenshot...!!

5960

5959

wysota
17th February 2011, 21:43
Use the level-of-detail information that you can query for in the item's paint() routine. Or use QFontMetrics to calculate the elided text based on the real rectangle occupied by the item. Which to choose depends on what you actually want to do.