PDA

View Full Version : Why the background is not transparent?



SkripT
2nd May 2006, 18:31
Hi, I use the following code to obtain a window with the shape of the pixmap "tux.png". The problem is that the background is painted in black color. Where's the mistake? Thanks.


#include <QtGui>

int main( int argc, char **argv )
{
QApplication a( argc, argv );

QPixmap p("../tux.png");
if (p.mask().isNull())
{
QImage img("../tux.png");
if ( img.hasAlphaChannel() )
p.setMask(QBitmap::fromImage(img.createAlphaMask() ));
else
p.setMask( QBitmap::fromImage(img.createHeuristicMask()));
}
QWidget w(0, Qt::FramelessWindowHint);
QPalette palette = w.palette();
palette.setBrush(QPalette::Window, QBrush(p));
w.setPalette(palette);
w.setFixedSize(p.size() );
w.setMask(p.mask());
w.show();

return a.exec();
}

SkripT
2nd May 2006, 18:46
Sorry it's solved with the current version :rolleyes:

Chicken Blood Machine
2nd May 2006, 18:51
Can you verify if it is the createHeuristicMask() or the createAlphaMask() that is not working or is it both? Try commenting each out to see where the problem lies.

Then we can take it from there.

Edit: Oops, just saw your latest post. Ignore this.

SkripT
3rd May 2006, 10:14
Yes sorry Chicken Blood Machine, I think that the problem was that I was not drawing the pixmap p in the first version...

briahn06
9th May 2006, 02:17
I'm sorry... how did you get the background transparent? I've been having this same issue.