Results 1 to 2 of 2

Thread: label as a QGraphicsItem

  1. #1
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Thanks
    43
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default label as a QGraphicsItem

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: label as a QGraphicsItem

    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.

Similar Threads

  1. Replies: 15
    Last Post: 31st January 2020, 18:25
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. close window when click on a label
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 07:35
  4. Deleting a scene from QGraphicsItem mouseEvent
    By JonathanForQT4 in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2007, 11:27
  5. Replies: 1
    Last Post: 24th October 2006, 16:40

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.