PDA

View Full Version : Drawing QIconSet-s on a transparent QPixmap ?



ultr
11th March 2009, 21:24
Hello,

I use this code (Qt3) to draw two QIconSet-s (16x16) side by side on a transparent QPixmap, and then make another QIconSet (32x16) from it.



QPixmap pixmap( 32, 16 );
pixmap.fill( Qt::white );

QBitmap emptymask( 32, 16 );
emptymask.fill( Qt::color0 );
pixmap.setMask( emptymask );

QPainter painter( &pixmap );
painter.drawPixmap( QRect( 0, 0, 16, 16 ), icon1.pixmap() );
painter.drawPixmap( QRect( 16, 0, 16, 16 ), icon2.pixmap() );

return QIconSet( pixmap );


However the returned QIconSet is whole transparent.

When I comment out the QBitmap mask setting part (lines 4-6), the two small icons are drawn as expected, but the returned QIconSet has non-transparent, white background.

Is there a way to solve this?

aamer4yu
12th March 2009, 09:40
Why are you using mask ? I dont see any need for it..
You can fill the pixmap with transparent color -
pixmap.fill(Qt::transparent);

and then continue with drawing your icons :)

ultr
12th March 2009, 15:10
This is Qt3, and there is no Qt::transparent color here, nor a way to make QPixmap transparent in this way.
Of course I use pixmap.fill(Qt::transparent); in Qt4 version.


I have solved the problem by loading a transparent PNG into the first pixmap:



QPixmap emptypixmap;
uchar emptypng[] = {
0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00, 0x00,0x0d,0x49,0x48,0x44,0x52,0x00,0x00,0x02,0x00,
0x00,0x00,0x00,0x10,0x08,0x06,0x00,0x00,0x00,0x60, 0x31,0xc7,0x48,0x00,0x00,0x00,0x01,0x73,0x52,0x47,
0x42,0x00,0xae,0xce,0x1c,0xe9,0x00,0x00,0x00,0x09, 0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,
0x0b,0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00, 0x36,0x49,0x44,0x41,0x54,0x78,0xda,0xed,0xc1,0x31,
0x01,0x00,0x00,0x00,0xc2,0xa0,0xf5,0x4f,0xed,0x6f, 0x06,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0x37,0x80,0x10,0x00,0x01,0x73, 0x70,0xf6,0x31,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,
0x44,0xae,0x42,0x60,0x82
}; // transparent PNG image: 512px x 16px
emptypixmap.loadFromData( emptypng, sizeof(emptypng) );
QPixmap pixmap( 16+4+16, 16 );
copyBlt( &pixmap, 0 , 0, &emptypixmap , 0, 0, pixmap.width(), pixmap.height() );
copyBlt( &pixmap, 0 , 0, &(icon1.pixmap()), 0, 0, 16 , 16 );
copyBlt( &pixmap, 16+4, 0, &(icon2.pixmap()), 0, 0, 16 , 16 );
return QIconSet( pixmap );