PDA

View Full Version : Font is scaled



lni
29th January 2009, 17:34
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

lni
29th January 2009, 20:34
Anyone help pls?

wysota
29th January 2009, 21:31
Use QGraphicsItem::ItemIgnoresTransformations

lni
29th January 2009, 22:28
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...

wysota
29th January 2009, 23:57
Try this and it is not desirable. The text is now drawn in the wrong place...
You're on your own then.

lni
30th January 2009, 04:43
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?

wysota
30th January 2009, 10:26
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.

lni
30th January 2009, 14:20
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


GridNumberTextItem::GridNumberTextItem(...)
{
setFlag( QGraphicsItem::ItemIgnoresTransformations );
}

GridNumberTextItem::paint(...)
{
float val = 0;
while ( val <= 100 ) {
QPointF pos( val, 0 ); // <=== lose the trasform from the parent
painter->drawtext( pos, QString::number( val ) );
val += 10; // assuming step is 10
}
}


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!

wysota
30th January 2009, 18:50
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().

lni
30th January 2009, 19:37
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().

Do you mean I need to create many QGraphicsSimpleTextItem, with each item anchoring one grid point? If it is, then what if I have a million grid points? If not, can you give example or be more specific on how to do it?

Many thanks!

wysota
30th January 2009, 21:30
Do you mean I need to create many QGraphicsSimpleTextItem, with each item anchoring one grid point? If it is, then what if I have a million grid points?
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?

lni
30th January 2009, 21:54
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...

http://www.wellog.com/charts/shaly_sand_crossplot.jpg,