PDA

View Full Version : label as a QGraphicsItem



magland
29th December 2007, 16:51
What's the best way to make a QGraphicsItem that is a text label. I want to be able to align the text left, right, or center, from a given scene position. Do I need to create my own item, or can I use something like QGraphicsTextItem. Seems like QGraphicsTextItem does not allow to easily have setPos() represent the center of the text, for example. I already know that I need to use QGraphicsItem::ItemIgnoresTransformations.

wysota
29th December 2007, 17:24
The text item is fine. You can format and align the text any way you like though the document interface. As for the position, it is set relative to the parent, so if you want to centre the item on the scene, it's just a matter of calculating the position of the item using the scene width and the document width.