Originally Posted by
wysota
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(...)
{
}
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
}
}
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
}
}
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!
Bookmarks