Reputation: 10513
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?
To elaborate on the selected answer, I had to use QImage with a 24bits format (QImage::Format_ARGB8565_Premultiplied).
Upvotes: 0
Views: 750
Reputation: 2798
It looks like your Linux desktop has less colors than the Windows desktop. Have you checked your color settings on the CentOS desktop? Maybe you can try with an ordinary gradient and see how it looks:
class TestWidget: public QWidget {
public:
TestWidget(const char* imagePath)
{
setStyleSheet("background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #000000, stop: 1 #FFFFFF);");
}
};
The result should be a smooth horizontal gradient going from left to right.
Upvotes: 1