How to add transparency image in QT5.5.1 ?
-
Hi,
Now I am trying to add transparency image in qt.5.5.1. It is not working .But it is works well in qt 4.8.7.
My sample code is below,
QLabel* bg = new QLabel(&w); bg->setGeometry(100, 100, 200, 200); bg->show(); bg->setText("Hello"); bg->setStyleSheet("background-color: yellow;"); QPushButton* trans = new QPushButton(&w); trans->setGeometry(100, 100, 200, 200); QPixmap pixmap("transparent.png"); QIcon ButtonIcon(pixmap); trans->setIcon(ButtonIcon); trans->setIconSize(trans->size()); trans->setStyleSheet("background-color: rgba(255, 255, 255, 0);");This is works good in my pc. Am I need to change any code for qt 5.5.1? I am using X86 processor machine to run this code.
-
Hi
Are you sure it find the
QPixmap pixmap("transparent.png"); ? -
Ok so how does it "not work" ?
if i use your code ( with less trans ) i see

-
@mrjj Yes it found the image correctly. That's why it is working correctly in qt 4.8.7 version if I change the Kit configuration.
-
@Revathi said in How to add transparency image in QT5.5.1 ?:
if I change the Kit configuration.
Do you get any error after changing kit and running the same code with 5.5.1?
-
@Revathi
but what do you see ?
"It is not working" is a very poor description of your actual issue. -
@Revathi
Ok
Its working here with Qt5.12
Can you try
trans->setGeometry(100, 100, 180, 180);
( make buttons slightly less than yellow label) -
If I have changed geometry , the output will be like the above picture (in qt 5.5.1)
-
@mrjj the transparency is working now in qt 5.5.1. The code is given below,
QLabel* bg = new QLabel(&w); bg->setGeometry(100, 100, 200, 200); bg->show(); bg->setText("Hello"); bg->setStyleSheet("background-color: yellow;"); QPushButton* trans = new QPushButton(&w); trans->setGeometry(100, 100, 200, 200); QPixmap pixmap("transparent.png"); QIcon ButtonIcon(pixmap); trans->setIcon(ButtonIcon); trans->setIconSize(trans->size()); trans->setStyleSheet("border: None"); // It will make the image button as transparent trans->show();If I have changed background color of QLabel, it will transparent to the image button window.
I hope it may help. Thank you all.

