问题描述
QPushButton[type="buttonImgType"] {
image: url(:images/svg/myIcon.svg);
image-position: center;
min-height: 42px;
min-width: 130px;
}
我希望此按钮显示为已褪色,或者在未选中时显示 50% 透明 并显示完整图像。但是我找不到如何在 QT 中为按钮使用属性的方法。
有人知道怎么做吗?
解决方法
关注@Nejat answer:
您可以通过设置 QLabel 或 QPushbutton 的透明度 样式表:
ui->label->setStyleSheet("background-color: rgba(255,255,0);");
ui->button->setStyleSheet("background-color: rgba(255,0);");
您还可以将 background-color: rgba(255,0);
添加到设计器中小部件的 styleSheet 属性。
第四个参数是 alpha。你也可以有半透明 通过将 alpha 设置为大于零的某个值来设置小部件:
ui->button->setStyleSheet("background-color: rgba(255,50);");
可能重复 C++ over Qt : Controlling transparency of Labels and Buttons
,试试这种风格:
QPushButton
{
background-color: transparent;
border: none;
}
QPushButton:pressed
{
background-color:rgba(239,41,50);
border:2px solid black;
}
直到 QPushButton 有边框,它才不透明。