0

I have a pushbutton and was styled in QSS to assign an image like this

QPushButton[type="buttonImgType"] {
    image: url(:images/svg/myIcon.svg);
    image-position: center;
    min-height: 42px;
    min-width: 130px;
}

I want this button to display as if it is faded or like say 50% transparent when it is not checked and show full image when it is. But I cant find a way how to using the properties in QT for buttons.

Anyone have idea how to?

curiousJorgeXX
  • 363
  • 1
  • 10

2 Answers2

0

Following @Nejat answer:

You can set transparency of QLabel or QPushbutton by setting the stylesheet :

ui->label->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 0);");

You can also add background-color: rgba(255, 255, 255, 0); to the styleSheet property of the widget in the designer.

The fourth parameter is alpha. You can also have semi-transparent widgets by setting alpha to some value more than zero :

ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 50);");

Possible duplicate of C++ over Qt : Controlling transparency of Labels and Buttons

Eak'Lon
  • 46
  • 7
0

Try This Style :

QPushButton
{
   background-color: transparent;
   border: none;

}
QPushButton:pressed
{
   background-color:rgba(239, 41, 41,50);
   border:2px solid black;
}

until QPushButton has border it didn't transparent .

Parisa.H.R
  • 3,303
  • 3
  • 19
  • 38