我有一个按钮,并在QSS中设置了样式,以分配一个这样的图像
QPushButton[type="buttonImgType"] {
image: url(:images/svg/myIcon.svg);
image-position: center;
min-height: 42px;
min-width: 130px;
}
我希望这个按钮显示,就像它是褪色或喜欢,比如50%透明时,它没有被选中,并显示完整的图像时,它是。但是我找不到一种方法来使用QT中的属性来处理按钮。
有谁知道怎么做吗?
发布于 2021-07-08 19:02:24
关注@Nejat answer
可以通过设置样式表来设置QLabel或QPushbutton的透明度:
ui->标签->setStyleSheet(“background-color: rgba(255,255,255,0);");ui->button->setStyleSheet("background-color: rgba(255,255,255,0);");
您还可以在设计器中向小部件的styleSheet属性添加background-color:rgba(255, 255, 255, 0);
。
第四个参数是alpha。您还可以通过将alpha设置为大于零的某个值来获得半透明的小部件:
ui->按钮->setStyleSheet(“背景颜色: rgba(255,255,255,50);");
可能存在重复的C++ over Qt : Controlling transparency of Labels and Buttons
发布于 2021-07-09 04:21:33
尝试此样式:
QPushButton
{
background-color: transparent;
border: none;
}
QPushButton:pressed
{
background-color:rgba(239, 41, 41,50);
border:2px solid black;
}
直到QPushButton有了边框,它才是透明的。
https://stackoverflow.com/questions/68297280
复制相似问题