You are not logged in.

1

Wednesday, August 31st 2011, 1:16am

Widget showing up without a transparent background in QGraphicsView

When I was using QGridLayout to display my widgets, only the widget was shown and the part of the image that was transparent was not shown. Now I switched to using QGraphicsScene and QGraphicsView, and now my images have a gray background wherever they used to be transparent.

Source code

1
2
3
4
5
6
7
8
9
void Piece::paintEvent(QPaintEvent *)
{
string image = ":/images/" + color + piece + ".png";
pixmap.load(image.c_str());
//pixmap.setMask(pixmap.createMaskFromColor(QColor(240, 240, 240)));

QPainter paint(this);
paint.drawPixmap(0, 0, pixmap);
} 

That's how the image is displayed on my widget. When I used the code,

Source code

1
layout->addWidget(0,0,1,1);

the background is transparent. But when I use,

Source code

1
scene->addWidget(piece);

The widget has a gray background. How can I make it transparent? The full code can be found here if necessary (probably won't be necessary): https://github.com/gsingh93/Chess

2

Sunday, September 4th 2011, 6:38pm

The solution was piece->setStyleSheet("background-color: transparent;");