Results 1 to 7 of 7

Thread: To Draw Text at given position on QGraphicsScene

  1. #1
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default To Draw Text at given position on QGraphicsScene

    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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: To Draw Text at given position on QGraphicsScene

    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.

  3. #3
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: To Draw Text at given position on QGraphicsScene

    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

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: To Draw Text at given position on QGraphicsScene

    QGraphicsWidgetis inherited by QGraphicsObjectand QGraphicsLayoutItem.
    QGraphicsObjectis inherited by QObject and QGraphicsItem.

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

  5. #5
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: To Draw Text at given position on QGraphicsScene

    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.

  6. #6
    Join Date
    Jan 2010
    Posts
    95
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: To Draw Text at given position on QGraphicsScene

    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

  7. #7
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: To Draw Text at given position on QGraphicsScene

    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.

Similar Threads

  1. Replies: 4
    Last Post: 30th October 2009, 07:36
  2. QGraphicsScene Position Problem
    By addu in forum Qt Programming
    Replies: 14
    Last Post: 22nd July 2009, 14:38
  3. Position of Items in QGraphicsScene/QGraphicsView
    By StefanK2 in forum Qt Programming
    Replies: 11
    Last Post: 7th July 2009, 14:04
  4. Position in a QPixMap created from a QGraphicsScene
    By stevel in forum Qt Programming
    Replies: 8
    Last Post: 8th April 2009, 22:39
  5. Draw QtCanvasElipse on mouse press event position
    By YuriyRusinov in forum Newbie
    Replies: 1
    Last Post: 31st May 2006, 11:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.