Results 1 to 5 of 5

Thread: Why the background is not transparent?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Why the background is not transparent?

    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.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main( int argc, char **argv )
    4. {
    5. QApplication a( argc, argv );
    6.  
    7. QPixmap p("../tux.png");
    8. if (p.mask().isNull())
    9. {
    10. QImage img("../tux.png");
    11. if ( img.hasAlphaChannel() )
    12. p.setMask(QBitmap::fromImage(img.createAlphaMask()));
    13. else
    14. p.setMask( QBitmap::fromImage(img.createHeuristicMask()));
    15. }
    16. QWidget w(0, Qt::FramelessWindowHint);
    17. QPalette palette = w.palette();
    18. palette.setBrush(QPalette::Window, QBrush(p));
    19. w.setPalette(palette);
    20. w.setFixedSize(p.size() );
    21. w.setMask(p.mask());
    22. w.show();
    23.  
    24. return a.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by SkripT; 2nd May 2006 at 17:44.

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. QLCDNumber with transparent background?
    By PolyVox in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2008, 05:34
  3. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  4. Replies: 3
    Last Post: 8th December 2006, 18:51
  5. Replies: 1
    Last Post: 5th April 2006, 16:44

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.