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.
{
string image = ":/images/" + color + piece + ".png";
pixmap.load(image.c_str());
//pixmap.setMask(pixmap.createMaskFromColor(QColor(240, 240, 240)));
paint.drawPixmap(0, 0, pixmap);
}
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);
}
To copy to clipboard, switch view to plain text mode
That's how the image is displayed on my widget. When I used the code,
layout->addWidget(0,0,1,1);
layout->addWidget(0,0,1,1);
To copy to clipboard, switch view to plain text mode
the background is transparent. But when I use,
scene->addWidget(piece);
scene->addWidget(piece);
To copy to clipboard, switch view to plain text mode
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
Bookmarks