Results 1 to 5 of 5

Thread: Keep text readable after flip & rotation of QGraphicsItem

  1. #1
    Join Date
    May 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Keep text readable after flip & rotation of QGraphicsItem

    I have a QGraphicsItem class which contains a QGraphicsItem inside it. The nested QGraphicsItem contains the text. When I rotate or flip the top level QGraphicsItem the text of the nested item becomes rotates & flips also and becomes un-readable. How can ensure the text always remain readable?

    Adeel.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Keep text readable after flip & rotation of QGraphicsItem

    Set the ItemIgnoresTransformations flag on the text item using QGraphicsItem::setFlag().

  3. #3
    Join Date
    May 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Keep text readable after flip & rotation of QGraphicsItem

    I should have mentioned it before. I already tried that flag and it removes all the transformations. I want to keep some transformations especially scaling. Well the flipping is done using the scaling but if i set ItemIgnoresTransformations flag then my text appears bigger than the parent item.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Keep text readable after flip & rotation of QGraphicsItem

    Then you probably need to derive from QGraphicsSimpleTextItem / QGraphicsTextItem, whichever you use, and override the paint method. In it, you save the QPainter's state, set a new rotation transform, call the base class paint method with the modified QPainter, then restore the QPainter state.

    You could first retrieve the painter's QTransform and check for isRotated() if you want to optimize a bit.

  5. The following user says thank you to d_stranz for this useful post:

    adeas31 (3rd March 2016)

  6. #5
    Join Date
    May 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Keep text readable after flip & rotation of QGraphicsItem

    I am using QGraphicsItem and already using the paint method. I solved the issue by checking the flipping and rotation state of the parent item and then doing exactly the opposite of it on the painter. So my solution is working for all the cases I tried. But just wondering if Qt has some built in support for such thing perhaps in more specific class like QGraphicsTextItem.

Similar Threads

  1. Replies: 0
    Last Post: 28th December 2013, 04:39
  2. {x,y,z}Rotation property of QGraphicsItem has gone?
    By Giga in forum Qt Programming
    Replies: 7
    Last Post: 10th September 2009, 12:02
  3. Replies: 5
    Last Post: 20th January 2009, 09:13
  4. Problem with rotation of QGraphicsItem
    By ashishsaryar in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2008, 15:03
  5. rotation of an animated QGraphicsItem
    By darksaga in forum Qt Programming
    Replies: 9
    Last Post: 9th September 2007, 08:11

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.