Results 1 to 5 of 5

Thread: QImage Transparency

  1. #1
    Join Date
    Mar 2011
    Posts
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QImage Transparency

    Hi,


    I am trying to clip an image with a curve by setting the corresponding to-be-clipped pixels to transparent. I am using qt3 and the code follows for transparency does not work.
    Qt Code:
    1. image.setAlphaBuffer(TRUE);
    2. QColor trans(Qt::color0.rgb());
    3. // QRgb mycol = qRgba ( 255, 255, 255,0 );
    4. // trans.setRgb(mycol);
    5. for (int i = 0; i < img_height; i++){
    6. for (int j = 0; j < img_width; j++){
    7. if (tempimg[i][j] == 0)
    8. image.setPixel(i,j, trans.rgb());
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas what I'm doing wrong?

    Thank you,
    Sapal

  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: QImage Transparency

    Any ideas what I'm doing wrong?
    You are not setting the alpha channel.
    Use rgba() not rgb().
    ==========================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 2011
    Posts
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QImage Transparency

    The problem is that I'm using qt3 and QColor takes only 3 arguments(r,g,b) and the thing is the setPixel in QImage only uses r,g,b. I really don't know how to set and check the alpha value for the pixel in qt3!! any suggestions?

    Thank you for your help

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QImage Transparency

    Have you tried using the documentation?

    Qt 3's support for transparency is only fair. You should switch to Qt 4, although you can do what you're after in Qt 3.

    You might try setting the alpha value to an intermediate value, like 125, to make sure transparency is working in the first place.
    Last edited by SixDegrees; 28th July 2011 at 07:57.

  5. #5
    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: QImage Transparency

    The problem is that I'm using qt3 and QColor takes only 3 arguments(r,g,b) and the thing is the setPixel in QImage only uses r,g,b.
    Not true.
    http://doc.qt.nokia.com/3.3/qimage.html#setPixel
    And
    http://doc.qt.nokia.com/3.3/qcolor.html#qRgba
    ==========================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.

Similar Threads

  1. QImage, PNG ad Transparency
    By Rebe in forum Qt Programming
    Replies: 5
    Last Post: 30th May 2014, 07:41
  2. Replies: 5
    Last Post: 16th May 2011, 21:15
  3. Transparency ... Again
    By EricF in forum Qt Programming
    Replies: 4
    Last Post: 1st December 2007, 19:52
  4. Replies: 3
    Last Post: 15th March 2006, 11:44
  5. transparency
    By roms18 in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2006, 19:38

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.