Ok, fill() corrupts the image. Use this instead:
#include <QApplication>
#include <QImage>
#include <QLabel>
#include <QPalette>
#include <QVBoxLayout>
#include <QPixmap>
#include <QPainter>
int main(int argc, char **argv){
pal.
setColor(QPalette::Window, Qt
::red);
l->addWidget(lab);
wgt.setLayout(l);
painter.
fillRect(alpha.
rect(),
QColor(127,
127,
127));
painter.end();
image.setAlphaChannel(alpha);
lab->setPixmap(pix);
wgt.show();
return app.exec();
}
#include <QApplication>
#include <QImage>
#include <QLabel>
#include <QPalette>
#include <QVBoxLayout>
#include <QPixmap>
#include <QPainter>
int main(int argc, char **argv){
QApplication app(argc, argv);
QWidget wgt;
QPalette pal = wgt.palette();
pal.setColor(QPalette::Window, Qt::red);
QLabel *lab = new QLabel;
QVBoxLayout *l = new QVBoxLayout;
l->addWidget(lab);
wgt.setLayout(l);
QImage image("test.jpg");
QImage alpha = image;
QPainter painter(&alpha);
painter.fillRect(alpha.rect(), QColor(127,127,127));
painter.end();
image.setAlphaChannel(alpha);
QPixmap pix = QPixmap::fromImage(image);
lab->setPixmap(pix);
wgt.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks