Results 1 to 5 of 5

Thread: Why the background is not transparent?

  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 18:44.

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

    Default Re: Why the background is not transparent?

    Sorry it's solved with the current version

  3. #3
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why the background is not transparent?

    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.
    Save yourself some pain. Learn C++ before learning Qt.

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

    Default Re: Why the background is not transparent?

    Yes sorry Chicken Blood Machine, I think that the problem was that I was not drawing the pixmap p in the first version...

  5. #5

    Default Re: Why the background is not transparent?

    I'm sorry... how did you get the background transparent? I've been having this same issue.

Similar Threads

  1. How to set Qt window transparent?
    By montylee in forum Qt Programming
    Replies: 17
    Last Post: 24th December 2013, 21:11
  2. QLCDNumber with transparent background?
    By PolyVox in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2008, 06:34
  3. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 18:52
  4. Replies: 3
    Last Post: 8th December 2006, 19:51
  5. Replies: 1
    Last Post: 5th April 2006, 17: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.