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 )
{
if (p.mask().isNull())
{
if ( img.hasAlphaChannel() )
p.
setMask(QBitmap::fromImage(img.
createAlphaMask()));
else
p.
setMask( QBitmap::fromImage(img.
createHeuristicMask()));
}
QWidget w
(0, Qt
::FramelessWindowHint);
w.setPalette(palette);
w.setFixedSize(p.size() );
w.setMask(p.mask());
w.show();
return a.exec();
}
#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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks