I’m trying to draw a transparent PNG file inside a QWidget. The problem is, I’m getting different results on Windows and Linux.
I uploaded the image, Windows screenshot, and Linux screenshot. The difference could be seen easily.
The code I used for testing is –
class TestWidget: public QWidget {
public:
TestWidget(const char* imagePath)
{
m_pixmap = QPixmap(imagePath);
setStyleSheet("background-color: black");
}
protected:
virtual void paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap(QPoint(0,0), m_pixmap);
}
QPixmap m_pixmap;
};
And the main function looks like this:
TestWidget* testWidget = new TestWidget(imagePath);
testWidget->setGeometry(0, 10, 1024, 1024);
testWidget->show();
I’m using Qt 4.5.1/4.7.2, Windows XP and CentOS 5.5.
Any ideas what could be the problem?
Edit:
To elaborate on the selected answer, I had to use QImage with a 24bits format (QImage::Format_ARGB8565_Premultiplied).
Try using QImage instead of QPixmap.