Parent item has a scale transform set, the child item's font is automatically scaled. How can I drawText with orignal font (without scaling from parent) at the same location?
Thanks
Parent item has a scale transform set, the child item's font is automatically scaled. How can I drawText with orignal font (without scaling from parent) at the same location?
Thanks
Last edited by lni; 29th January 2009 at 20:34.
Anyone help pls?
Use QGraphicsItem::ItemIgnoresTransformations
Try this and it is not desirable. The text is now drawn in the wrong place...
I can use QPen::setCosmetic, I think QFont should have similar property. When doing transform, most of the time we want to keep the font size unchanged...
By the way, setScalable or setTransformable is much more intuitive...
This is terrible, I have spent 6 hours on this and found nothing!
All I want is not to rotate or scale my font. QGraphicsItem::ItemIgnoresTransformations does ignore the scaling and rotating, but it also lose the location.
Can some one please give an example?
If you set the bounding rect of the text item correctly, you won't lose position, just anchor the (0,0) point to the position where you want it to be.
I am trying to print the grid number along axis, such as 0, 10, 20, 30.... This GridNumberTextItem is derived from QGraphicsItem, so here is what I do
Qt Code:
GridNumberTextItem::GridNumberTextItem(...) { } GridNumberTextItem::paint(...) { float val = 0; while ( val <= 100 ) { val += 10; // assuming step is 10 } }To copy to clipboard, switch view to plain text mode
In doing so, I lose transform for "pos", so the text is drawn in wrong place. The parent item has a scaling transform. How can I fix this problem? Thanks!
I'm not sure why you use some "pos" inside your paint routine. You should anchor the text item to the value you want it to represent. Then you can make it ignore transformations and rely purely on setPos().
We were talking about fonts here so I more meant the labels describing points. And yes, I meant make each label a separate item.
I'm not exactly sure what you are doing - it is probably some kind of graph or canvas and a ruler. Have you thought about making the ruler a separate widget?
I will investigate the separate widget option then...
Yes, it is for graph plot - to plot, for instance, time vs. temperature, and I need to label the X-axis (50, 60, 70, ...) and Y-axis (2.1, 2.2, 2.3, 2.4...). Making each tick as a separated item is too much in this case. I have been using Qt for some time, but only last week I discovered QGraphicsItem, so it is quite new to me, if you can point me to some correct direction, I would very much appreciate...I have run all the examples in the graphics section though...
But if you can provide QFont::Cosmetic, just like QPen, life would be much much easier...
It is similar to the one below. As you can see, if I zoom in, it look ugly if the label text get scaled, especially if I zoom it with different scale in X and Y, the label is totally distorted, which brings no value to the users...
,
Bookmarks