Results 1 to 6 of 6

Thread: Add a QGraphicsTextItem with a gradient

  1. #1
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Add a QGraphicsTextItem with a gradient

    Hello!

    I'd like to add a text with a gradient like this
    http://doc.qt.nokia.com/4.0/qt4-arth...transformation

    But I'm using a QGraphicsScene (and it doesn't have a setPen() method) and I should add a QGraphicsTextItem...is there a way to do so?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Add a QGraphicsTextItem with a gradient

    One way is to subclass QGraphicsTextItem and do the painting yourself. Depending on how complicated your text actually is.

  3. #3
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add a QGraphicsTextItem with a gradient

    I'd like to build up a gradient system for a general text (for example it should work for both "Hello World!" and "Last week I went in Canada and met John. Then...").
    How can I do the painting myself? I'm not sure about the functions I have to use to make the painting...

    thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Add a QGraphicsTextItem with a gradient

    The question is more if you plan to use HTML within your item. As for normal texts, you have to reimp the paint method and use the painter. Then you could set the gradient to the pen. See QGraphicsItem::paint(). You can also try to just set the pen and call the base class implementation with the modified painter.

  5. #5
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add a QGraphicsTextItem with a gradient

    I'll try it and let you know...thanks!

  6. #6
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add a QGraphicsTextItem with a gradient

    I've solved in a very simple way (but it's not the more general-purpose way). I used this site
    http://www.tektek.org/color/
    to generate a HTML text with a "gradient" color. so I call the setHTML() method of the qGraphicsTextItems passing the HTML strings..

Similar Threads

  1. Rotating Gradient
    By JeffC in forum Newbie
    Replies: 3
    Last Post: 3rd June 2012, 11:11
  2. Replies: 51
    Last Post: 26th November 2010, 13:24
  3. getting gradient colors
    By venkat.godavarthi in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2009, 13:36
  4. QPainter Gradient
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 12:53
  5. gradient background
    By drkbkr in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2006, 16:10

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
  •  
Qt is a trademark of The Qt Company.