I want to create a button that displays a given image with a transparent background. I am using the code segment below:
ui->setupUi(this);
this->setFixedSize(width, height);
QPixmap* orgPixmap = new QPixmap(":/images/a.png");
QSize size(this->width(), this->height());
QPixmap resizePixmap(orgPixmap->scaled(size));
QPalette palette;
palette.setBrush(this->backgroundRole(), QBrush(resizePixmap));
this->setPalette(palette);
ui->toolButton->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
ui->toolButton->setFixedSize(64, 64);
ui->toolButton->setIconSize(QSize(64, 64));
ui->toolButton->setIcon( QIcon(":/images/add.png") );
At the top of the widget, I have added a button with an icon. This is a blue circle with a transparent background. However, when I deploy and run my code on an Android device, the button is displayed with an opaque background with white colour.
Please see the picture:
I have tried to force the transparency for the button using the following code:
QColor transparent_color(0,0,0,0);
QPalette button_palette(ui->pushButton->palette());
button_palette.setColor(QPalette::Button, transparent_color);
ui->toolButton->setPalette(button_palette);
The above code did not seem to have the desired effect as I had expected. I would like to know what the problem might be and how to fix it.