Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.0.0
-
None
Description
When we change the transparency of the image, drawing it onto the window will cause the window to be transparent.
void MainWindow::paintEvent(QPaintEvent *event) { QImage image("/home/thx/Desktop/3.png","png"); QPainter pa(&image); pa.setCompositionMode(QPainter::CompositionMode_DestinationIn); pa.fillRect(image.rect(), QColor(0, 0, 0, 255 * 0.2)); pa.end(); QPainter painter(this); painter.drawImage(rect(),image); }
The following code can also reproduce this problem
QPainter paintertemp(this);
QImage imgtmp(size(),QImage::Format::Format_RGB32);
memset(imgtmp.bits(),0,imgtmp.sizeInBytes());
paintertemp.drawImage(rect(),imgtmp);
==============================================================
The study found that when test.png does not have a transparency attribute, the format of QImage is Format_RGB, and the use of fillRect changes the image transparency channel. When drawing, it will directly cover rasterBuffer and cause the background to be transparent.
In fillrect(), should it be judged whether the PainterDevice has a transparent channel, instead of modifying it directly?