Requirement: Non-sensing button (transparent button)
Reference: The same is the case, the following problem was encountered, and the elder brother gave the reason
-
The effect of setFlat(true) is: do not click the button to be transparent, click the button, and the original outline and color of the button can be displayed;
-
The effect of background-color: rgba(0, 0, 0, 0) is: do not click the button to be transparent, click the button, the outline of the button is displayed, but the button is black;
Solve the embedded device, the button press background color is black or different transparent
- Use the setFlat function to achieve the effect of button transparency
QPushButton *mode =new QPushButton(this);
mode->setFlat(true);//实现按钮透明的效果
But sometimes it is not necessarily the setting
true
that will take effect, but the settingfalse
will take effect
solve the case
- No font key pressed opaque
// 不生效
bt->setFlat(true);
bt->setFocusPolicy(Qt::NoFocus);
bt->setStyleSheet("QPushButton{
font-size:24px;
color:#ffffff;text-align:left;border-color:rgba(0,0,0,0);}");
// 生效
bt->setFlat(false);
bt->setFocusPolicy(Qt::NoFocus);
bt->setStyleSheet("border:nonr;background:transparent;
color:#ffffff;text-align:left;font-size:24px;");
- There are font keys pressed opaque
// 不好使
bt->setStyleSheet("QPushButton{
font-size:%24px;color:#ffffff;
text-align:left;background-color:rgba(0,0,0,0);}");
// 好使
bt->setStyleSheet("border:nonr;background:transparent;
color:#ffffff;text-align:left;font-size:24px;");
- In this way, you can press transparent, no need to set a blank transparent image