Results 1 to 6 of 6

Thread: SVG to alpha channel QPixmaps?

  1. #1
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question SVG to alpha channel QPixmaps?

    I have an image in *.svg format. I want to load and convert it into a QPixmap object, where the image is opaque where the svg vector lines dictate color, and transparent everwhere else.

    I'm currently doing this:
    Qt Code:
    1. QSvgRenderer renderer;
    2. renderer.load("images/my-logo.svg");
    3. QPixmap image(renderer.defaultSize());
    4. QPainter painter(&image);
    5. renderer.render(&painter);
    6. QLabel *logoLabel = new QLabel(this);
    7. logoLabel->setPixmap(image);
    To copy to clipboard, switch view to plain text mode 
    It puts the svg image into the QLabel, but with an opaque background.
    How can I make it with a transparent background?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SVG to alpha channel QPixmaps?

    I am not sure if the svg renderer can handle that.
    Are you sure the pixmap is not transparent?
    Have you tried saving it and opening it in a viewer or something?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: SVG to alpha channel QPixmaps?

    Try:
    Qt Code:
    1. image.fill(Qt::transparent);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    WinchellChung (24th August 2007)

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SVG to alpha channel QPixmaps?

    Quote Originally Posted by jpn View Post
    Try:
    Qt Code:
    1. image.fill(Qt::transparent);
    To copy to clipboard, switch view to plain text mode 
    Are you sure the renderer won't overwrite all the pixels in the pixmap?

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: SVG to alpha channel QPixmaps?

    Quote Originally Posted by marcel View Post
    Are you sure the renderer won't overwrite all the pixels in the pixmap?
    Yes, I tested it.
    J-P Nurmi

  7. #6
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: SVG to alpha channel QPixmaps?

    Quote Originally Posted by jpn View Post
    Try:
    Qt Code:
    1. image.fill(Qt::transparent);
    To copy to clipboard, switch view to plain text mode 
    Works like magic! Thanks!

Similar Threads

  1. Replies: 2
    Last Post: 3rd November 2006, 22:20
  2. image alpha
    By murko81 in forum Qt Programming
    Replies: 13
    Last Post: 28th October 2006, 19:31
  3. Alpha channel weirdness with QGLContext
    By renaissanz in forum Qt Programming
    Replies: 2
    Last Post: 15th 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.