Results 1 to 10 of 10

Thread: transparency, setMask, createHeuristicMask, createMaskFromColor, QPixmap

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: transparency, setMask, createHeuristicMask, createMaskFromColor, QPixmap

    Try this:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MaskedLabel : public QLabel
    4. {
    5. protected:
    6. void resizeEvent(QResizeEvent* event)
    7. {
    8. QLabel::resizeEvent(event);
    9.  
    10. QPixmap pixmap(size());
    11. pixmap.fill(Qt::transparent);
    12. QPainter::setRedirected(this, &pixmap);
    13. QPaintEvent pe(rect());
    14. paintEvent(&pe);
    15. QPainter::restoreRedirected(this);
    16. setMask(pixmap.mask());
    17. }
    18. };
    19.  
    20. int main(int argc, char* argv[])
    21. {
    22. QApplication a(argc, argv);
    23. QLabel* label = new MaskedLabel();
    24. label->setText("Qt Centre!");
    25. QFont font = label->font();
    26. font.setPointSize(72);
    27. label->setFont(font);
    28. label->show();
    29. return a.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  2. The following 2 users say thank you to jpn for this useful post:

    TheKedge (6th February 2007), yurenjimi (14th January 2009)

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.