Results 1 to 20 of 29

Thread: How to remove background

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #17
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: How to remove background

    to durbrak:
    Qt Code:
    1. CTestWidget::CTestWidget(QWidget* parent )
    2. :QWidget( parent )
    3. {
    4. setWindowFlags( Qt::FramelessWindowHint );
    5. setFixedSize( 400, 400 );
    6. mPixmap = QPixmap( "C:\\ellipse.png" );
    7. QBitmap mask = mPixmap.createHeuristicMask(true);
    8. setMask( mask );
    9. }
    10.  
    11. CTestWidget::~CTestWidget()
    12. {
    13. }
    14.  
    15. void CTestWidget::paintEvent(QPaintEvent* e)
    16. {
    17. QPainter p( this );
    18. p.drawPixmap( 0, 0, mPixmap );
    19. }
    To copy to clipboard, switch view to plain text mode 

    I knew I did it some time ago.
    I attached a screen of how it looks.
    The png is just a black ellipse on a white background.
    The method is limited because it does not work when the image you want to display contains transparent shadings ( such as shadows ).
    However, you can give the whole masked widget a shadow if you set the flags Qt::FramessWindowHint | Qt::Popup.

    Although, never tested it on Mac.

    regards
    Last edited by marcel; 20th May 2007 at 01:07.

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
  •  
Qt is a trademark of The Qt Company.