Results 1 to 3 of 3

Thread: Drawing QIconSet-s on a transparent QPixmap ?

  1. #1
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Question Drawing QIconSet-s on a transparent QPixmap ?

    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.

    Qt Code:
    1. QPixmap pixmap( 32, 16 );
    2. pixmap.fill( Qt::white );
    3.  
    4. QBitmap emptymask( 32, 16 );
    5. emptymask.fill( Qt::color0 );
    6. pixmap.setMask( emptymask );
    7.  
    8. QPainter painter( &pixmap );
    9. painter.drawPixmap( QRect( 0, 0, 16, 16 ), icon1.pixmap() );
    10. painter.drawPixmap( QRect( 16, 0, 16, 16 ), icon2.pixmap() );
    11.  
    12. return QIconSet( pixmap );
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drawing QIconSet-s on a transparent QPixmap ?

    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

  3. #3
    Join Date
    Nov 2006
    Location
    Poland
    Posts
    35
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Lightbulb Re: Drawing QIconSet-s on a transparent QPixmap ?

    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:

    Qt Code:
    1. QPixmap emptypixmap;
    2. uchar emptypng[] = {
    3. 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,0x00,0x00,0x02,0x00,
    4. 0x00,0x00,0x00,0x10,0x08,0x06,0x00,0x00,0x00,0x60,0x31,0xc7,0x48,0x00,0x00,0x00,0x01,0x73,0x52,0x47,
    5. 0x42,0x00,0xae,0xce,0x1c,0xe9,0x00,0x00,0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0b,0x13,0x00,0x00,
    6. 0x0b,0x13,0x01,0x00,0x9a,0x9c,0x18,0x00,0x00,0x00,0x36,0x49,0x44,0x41,0x54,0x78,0xda,0xed,0xc1,0x31,
    7. 0x01,0x00,0x00,0x00,0xc2,0xa0,0xf5,0x4f,0xed,0x6f,0x06,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    8. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    9. 0x00,0x00,0x00,0x80,0x37,0x80,0x10,0x00,0x01,0x73,0x70,0xf6,0x31,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,
    10. 0x44,0xae,0x42,0x60,0x82
    11. }; // transparent PNG image: 512px x 16px
    12. emptypixmap.loadFromData( emptypng, sizeof(emptypng) );
    13. QPixmap pixmap( 16+4+16, 16 );
    14. copyBlt( &pixmap, 0 , 0, &emptypixmap , 0, 0, pixmap.width(), pixmap.height() );
    15. copyBlt( &pixmap, 0 , 0, &(icon1.pixmap()), 0, 0, 16 , 16 );
    16. copyBlt( &pixmap, 16+4, 0, &(icon2.pixmap()), 0, 0, 16 , 16 );
    17. return QIconSet( pixmap );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to set Qt window transparent?
    By montylee in forum Qt Programming
    Replies: 17
    Last Post: 24th December 2013, 20:11
  2. drawing on a QPixmap or QImage
    By gren15 in forum Newbie
    Replies: 15
    Last Post: 3rd March 2009, 17:48
  3. Replies: 4
    Last Post: 28th August 2008, 13:13
  4. Drawing speed: QPixmap vs QPicture
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2008, 19:17
  5. Regarding drawing on Transparent Window
    By Shalabh in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2007, 10:32

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.