Results 1 to 6 of 6

Thread: QPixmap::grabWidget and QWidget::render loose alpha

  1. #1
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QPixmap::grabWidget and QWidget::render loose alpha

    I'm doing transparency on my widget and when trying to render it in a QPixmap or QImage, the alpha is lost. QPixmap::hasAlphaChannel returns true but the actual alpha channel is full opaque.

    The transparency works for the widget on the screen but not in the QPixmap.

    Any hint ?

  2. #2
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap::grabWidget and QWidget::render loose alpha

    erm.... you render the image into a pixmap. the widget itself has no background, with which it coul be transpariced(haha, dont know if this word exists, hope you understand what i mean).
    if you want transparency, render the parent widget and draw the child onto it.

  3. #3
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap::grabWidget and QWidget::render loose alpha

    Yeah it makes sense however it doesn't work. In fact if I only render the region of the parent widget that shows my widget, the transparency gets applied in the child widget but the alpha channel of the resulting pixmap is still full opaque.

    I wouldn't mind if the actual rendering was full opaque but would like to get my alpha channel good.

  4. #4
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap::grabWidget and QWidget::render loose alpha

    Well ... I finally made it. It appears that (I still don't know why though) QPixmap can't do it but using a QImage with Format_ARGB32 format, the widget renders opaque but the alpha channel it returns is the right one.

  5. #5
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap::grabWidget and QWidget::render loose alpha

    hm... could you attach some code?
    i would like to test it here.

  6. #6
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPixmap::grabWidget and QWidget::render loose alpha

    hi,
    i think you just need no prepare a pixmap on which you are drawing widgets
    Qt Code:
    1. QPixmap pix;
    2. pix.fill(QColor(0,0,0,0));
    To copy to clipboard, switch view to plain text mode 
    If you are drawing items with transparency on something that is non transparent you'll see parts of old images contents on places where widgets are transparent so you need to draw them on transparent pixmap.
    Last edited by jpn; 13th March 2008 at 07:00. Reason: missing [code] tags
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

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.