Solved.
QImage dissociates alpha and RGB channel.
void qkColorPixmapPrivate
::refreshPixmap(const QColor & color
) {
Q_Q(qkColorPixmap);
if (this->color == color) return;
QImage image
= basePixmap.
toImage();
QImage alpha
= image.
alphaChannel();
int width = basePixmap.width();
int height = basePixmap.height();
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int a = qAlpha(image.pixel(j, i));
if (a > 0)
{
image.setPixel(j, i,
qRgb(color.red(),
color.green(),
color.blue()));
alpha.setPixel(j, i, a);
}
}
}
image.setAlphaChannel(alpha);
q
->QPixmap
::operator=(QPixmap::fromImage(image
));
this->color = color;
}
void qkColorPixmapPrivate::refreshPixmap(const QColor & color)
{
Q_Q(qkColorPixmap);
if (this->color == color) return;
QImage image = basePixmap.toImage();
QImage alpha = image.alphaChannel();
int width = basePixmap.width();
int height = basePixmap.height();
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int a = qAlpha(image.pixel(j, i));
if (a > 0)
{
image.setPixel(j, i,
qRgb(color.red(),
color.green(),
color.blue()));
alpha.setPixel(j, i, a);
}
}
}
image.setAlphaChannel(alpha);
q->QPixmap::operator=(QPixmap::fromImage(image));
this->color = color;
}
To copy to clipboard, switch view to plain text mode
Bookmarks