14 QLabel*
lbl(
const QPainter::CompositionMode& mode)
16 QLabel* plbl =
new QLabel;
17 plbl->setFixedSize(100, 100);
19 QRect rect(plbl->contentsRect());
22 QImage sourceImage(rect.size(), QImage::Format_ARGB32_Premultiplied);
23 sourceImage.fill(QColor(0, 0, 0, 0));
24 painter.begin(&sourceImage);
25 painter.setRenderHint(QPainter::Antialiasing,
true);
26 painter.setBrush(QBrush(QColor(0, 255, 0)));
27 painter.drawPolygon(QPolygon() << rect.bottomLeft()
28 << QPoint(rect.center().x(), 0)
33 QImage resultImage(rect.size(), QImage::Format_ARGB32_Premultiplied);
34 painter.begin(&resultImage);
35 painter.setRenderHint(QPainter::Antialiasing,
true);
36 painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
37 painter.setPen(QPen(QColor(0, 255, 0), 4));
38 painter.setBrush(QBrush(QColor(255, 0, 0)));
39 painter.drawEllipse(rect);
40 painter.setCompositionMode(mode);
41 painter.drawImage(rect, sourceImage);
44 plbl->setPixmap(QPixmap::fromImage(resultImage));
50 int main(
int argc,
char** argv)
52 QApplication app(argc, argv);
56 QGridLayout* pgrd =
new QGridLayout;
57 pgrd->addWidget(
lbl(QPainter::CompositionMode_Source), 0, 0);
58 pgrd->addWidget(
new QLabel(
"<CENTER>Source</CENTER>"), 1, 0);
59 pgrd->addWidget(
lbl(QPainter::CompositionMode_SourceOver), 0, 1);
60 pgrd->addWidget(
new QLabel(
"<CENTER>SourceOver</CENTER>"), 1, 1);
61 pgrd->addWidget(
lbl(QPainter::CompositionMode_SourceIn), 0, 2);
62 pgrd->addWidget(
new QLabel(
"<CENTER>SourceIn</CENTER>"), 1, 2);
63 pgrd->addWidget(
lbl(QPainter::CompositionMode_SourceOut), 0, 3);
64 pgrd->addWidget(
new QLabel(
"<CENTER>SourceOut</CENTER>"), 1, 3);
65 pgrd->addWidget(
lbl(QPainter::CompositionMode_SourceAtop), 0, 4);
66 pgrd->addWidget(
new QLabel(
"<CENTER>SourceAtop</CENTER>"), 1, 4);
67 pgrd->addWidget(
lbl(QPainter::CompositionMode_Clear), 0, 5);
68 pgrd->addWidget(
new QLabel(
"<CENTER>Clear</CENTER>"), 1, 5);
69 pgrd->addWidget(
lbl(QPainter::CompositionMode_Destination), 2, 0);
70 pgrd->addWidget(
new QLabel(
"<CENTER>Destination</CENTER>"), 3, 0);
71 pgrd->addWidget(
lbl(QPainter::CompositionMode_DestinationOver), 2, 1);
72 pgrd->addWidget(
new QLabel(
"<CENTER>DestinationOver</CENTER>"), 3, 1);
73 pgrd->addWidget(
lbl(QPainter::CompositionMode_DestinationIn), 2, 2);
74 pgrd->addWidget(
new QLabel(
"<CENTER>DestinationIn</CENTER>"), 3, 2);
75 pgrd->addWidget(
lbl(QPainter::CompositionMode_DestinationOut), 2, 3);
76 pgrd->addWidget(
new QLabel(
"<CENTER>DestinationOut</CENTER>"), 3, 3);
77 pgrd->addWidget(
lbl(QPainter::CompositionMode_DestinationAtop), 2, 4);
78 pgrd->addWidget(
new QLabel(
"<CENTER>DestinationAtop</CENTER>"), 3, 4);
79 pgrd->addWidget(
lbl(QPainter::CompositionMode_Xor), 2, 5);
80 pgrd->addWidget(
new QLabel(
"<CENTER>Xor</CENTER>"), 3, 5);
QLabel * lbl(const QPainter::CompositionMode &mode)
int main(int argc, char **argv)