Results 1 to 3 of 3

Thread: painting SVGs like text

  1. #1
    Join Date
    Jan 2014
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default painting SVGs like text

    I have written a QItemDelegate :: paint() function of a QTableView, where I draw a mixture of text and small symbols. Some of the symbols come from a symbol font but others have to be provided by my program. Like the text, the symbols are monochrome and should be displayed with the current pen color and background color, which change with the selection state of the table cell. What would be the best strategy?
    • I used to define the symbols in bitmap ressources where I used only three colors: black, white and gray (to create a basic anti aliasing) and I manually converted these three colors pixel by pixel to the current pen, backgrould and average color.
    • Now I would like to find a scalable solution with SVG graphics and true antialiasing. Do I really have to edit the color values of the SVG XML code at runtime (as described here http://www.qtcentre.org/archive/index.php/t-53946.html ) or is there a simpler solution?
    • I also thought of creating a font instead of SVG graphics. Is it possible to use a "private" font, which is not installed on the system? It should work under Windows and on a Mac.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: painting SVGs like text

    Quote Originally Posted by hartmut View Post
    I used to define the symbols in bitmap ressources where I used only three colors: black, white and gray (to create a basic anti aliasing) and I manually converted these three colors pixel by pixel to the current pen, backgrould and average color.
    If you can code drawing the symbols then you could paint fully anti-aliased versions of them in the correct colours in the paint() method of the delegate. QPixmapCache could also be useful to minimise reconstruction. You could also look into how you might use a monochrome mask with the image composition operations in Qt to produce your coloured foreground image.
    Now I would like to find a scalable solution with SVG graphics and true antialiasing. Do I really have to edit the color values of the SVG XML code at runtime (as described here http://www.qtcentre.org/archive/index.php/t-53946.html ) or is there a simpler solution?
    That is how SVG specifies colours, so that is how you change them. It need not be difficult:
    • Create the SVG.
    • Edit the file and replace the colour codes with markers, e.g. {{bg}} (or entities).
    • Ship this file with your project.
    • Load the SVG file once into a QByteArray at program start.

    When you need the SVG,
    • Copy the array
    • Use QByteArray::replace() to put your desired colours into the SVG
    • Feed the result to QSvgRenderer.

    Caching the results would be a good idea.
    I also thought of creating a font instead of SVG graphics. Is it possible to use a "private" font, which is not installed on the system? It should work under Windows and on a Mac.
    Yes. QFontDatabase::addApplicationFont(). The font file can come from a local file or Qt resource system.

  3. #3
    Join Date
    Jan 2014
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: painting SVGs like text

    Thanks a lot. I tried the font option and it works very well. That's a really elegant solution.

Similar Threads

  1. Replies: 1
    Last Post: 7th May 2011, 02:47
  2. Painting a right-aligned text
    By curreli in forum Newbie
    Replies: 2
    Last Post: 29th July 2010, 16:49
  3. SVGs with CSS support in QtSvg
    By lfranchi in forum Qt Programming
    Replies: 1
    Last Post: 27th December 2007, 05:20
  4. Loading SVGs in QIcon
    By adam_d in forum Qt Programming
    Replies: 1
    Last Post: 13th October 2007, 13:33
  5. Painting Rich Text
    By xanthine in forum Qt Programming
    Replies: 7
    Last Post: 15th April 2006, 23:35

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.