views:

47

answers:

1

I subclassed QGraphicsItem and reimplemented paint.
In paint I wrote something like this for labeling the item:

 painter->drawText("Test",10,40);

After some time I think It may be useful to handle labeling with seperate item. So I wrote something like this.

QGraphicsTextItem *label = new QGraphicsTextItem("TEST",this);
setPos(10,40);

But two "TEST" drawing do not appear in the same place on screen. I guess difference may be related with item coordinates - scene coordinates. I tried all mapFrom... and mapTo... combinations inside QGraphicsItem interface but no progress. I want to drawings to appear in the same place on screen.
What I miss?

+1  A: 

Hello,

I assume that you are using the same font size and type in both cases. If the difference in position is very small the reason can be the QGraphicTextItem is using some padding for the text it contains. I would try to use QGraphicsSimpleTextItem that is not going to add fancy stuff internally and see if you still have the same problem. The coordinates system is the same one if you use painter or setPost so that is not the problem. If this doesn't help I will suggest to specify the same rect for both to avoid Qt adding it owns separation spaces.

cnebrera