Try this:
#include <QtGui>
class MaskedLabel
: public QLabel{
protected:
{
pixmap.fill(Qt::transparent);
paintEvent(&pe);
setMask(pixmap.mask());
}
};
int main(int argc, char* argv[])
{
QLabel* label
= new MaskedLabel
();
label->setText("Qt Centre!");
QFont font
= label
->font
();
font.setPointSize(72);
label->setFont(font);
label->show();
return a.exec();
}
#include <QtGui>
class MaskedLabel : public QLabel
{
protected:
void resizeEvent(QResizeEvent* event)
{
QLabel::resizeEvent(event);
QPixmap pixmap(size());
pixmap.fill(Qt::transparent);
QPainter::setRedirected(this, &pixmap);
QPaintEvent pe(rect());
paintEvent(&pe);
QPainter::restoreRedirected(this);
setMask(pixmap.mask());
}
};
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
QLabel* label = new MaskedLabel();
label->setText("Qt Centre!");
QFont font = label->font();
font.setPointSize(72);
label->setFont(font);
label->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks