Results 1 to 3 of 3

Thread: QPixmap, PNG and Transparency

  1. #1
    Join Date
    Mar 2006
    Location
    Moldova
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QPixmap, PNG and Transparency

    Hi. I have a QPixmap object loaded from a PNG file with transparency. This pixmap is displayed onto a QGraphicsScene via an overloaded QGraphicsItem.

    I want the item to be more "lighty" when it is selected. I'm doing something like this:

    Qt Code:
    1. painter->fillRect(boundingRect(), Qt::gray);
    2. painter->setCompositionMode(QPainter::CompositionMode_Overlay);
    3. QRect rect = boundingRect().toRect();
    4. painter->drawPixmap(rect, myPixmap);
    To copy to clipboard, switch view to plain text mode 

    It's working, but the problem is that the transparent region of the pixmap becomes "grayed" too ...

    How can i draw the gray color just on the real icon, not touching the transparent region of the pixmap ?
    All Rights Reserved ...

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap, PNG and Transparency

    some ideas that come to mind:
    a. you can have a look at the effect classes see if you find something there
    b. you can have a light and dark version of your image in two pixmaps
    c. you can set a mask to your pixmap if its not changing size.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2006
    Location
    Moldova
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap, PNG and Transparency

    The first idea is what i wanted. Now using the QGraphicsOpacityEffect class.

    Thanks a lot
    All Rights Reserved ...

Similar Threads

  1. Replies: 9
    Last Post: 18th July 2011, 12:39
  2. Replies: 4
    Last Post: 28th August 2008, 13:13
  3. Replies: 1
    Last Post: 21st August 2008, 07:44
  4. Transparency ... Again
    By EricF in forum Qt Programming
    Replies: 4
    Last Post: 1st December 2007, 19:52
  5. Replies: 5
    Last Post: 9th April 2007, 14:26

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.