PDA

View Full Version : To Draw Text at given position on QGraphicsScene



volcano
3rd February 2010, 11:41
Hi,

I'm using QGraphicsScene to display QGraphicsWidgets contained in a QGraphicsLinearLayout.
The scene contains 7 objects and I need to draw text below the graphics object.
Is there any way to position the text using drawText().

Any suggestions would be of great help.

Thanks

aamer4yu
3rd February 2010, 12:59
You will need items to be placed in QGraphicsScene.
You can either create the text items and place them below desired items. OR you can combine text and graphicswidget into one item.

volcano
3rd February 2010, 14:26
Hi,

Thanks for the reply.
I figured how to get it painted but then can't get where the position of the graphicwidgets contained in a QGraphicsLinearLayout with respect to the QGraphicsScene. If can figure it out the location, I'll be able to paint text below it.
Any help would be appreciated
Thanks

aamer4yu
3rd February 2010, 16:02
QGraphicsWidget is inherited by QGraphicsObject and QGraphicsLayoutItem .
QGraphicsObject is inherited by QObject and QGraphicsItem.

There's a function QGraphicsItem::pos. Get the idea ? :rolleyes:

psih128
3rd February 2010, 17:08
Make the text item a child of the widget item by setting the parentItem property of the text item. This will cause the text item to be positioned relatively to the widget item.

volcano
4th February 2010, 04:47
Hi,
Thanks for all the suggestions.
But I don't want to make the text item the child of the graphicswidget because I'm applying shadow effect to the graphics widget and not to the text.
I want to place the text right below the graphics widget and give no effect to it.
Is there some way to find the relative postion of the graphics widget contained in a graphicslinearlayout with respect to the scene.
I have tried using scenePos but it gives information of the
Any suggestions would be of great help.

Thanks

psih128
4th February 2010, 09:16
when the text item is made a child of the widget item, it still may be positioned below the widget item. Parent-child relationship does not restrict the child item to be located outside of the bounds of the parent item. But if you still want to avoid nesting items, there are functions on graphics items, like QGraphicsItem::mapToItem, QGraphicsItem::mapFromParent, etc... Take a look at them.