当前位置: 代码迷 >> QT开发 >> QPushButton设立背景为透明。
  详细解决方案

QPushButton设立背景为透明。

热度:19   发布时间:2016-04-25 04:03:06.0
QPushButton设置背景为透明。。。
怎样设置按钮的背景为透明色啊???求指导。。。

------解决方案--------------------
试下qss吧

话说我试过在一个程序的按钮里面用qss
然后qss的效果是透明渐变什么的

qss样式:
 QPushButton {
   color: rgb(0,88,152)
   background-color: rgba(97%,80%,9%,50%)
}

添加一个*.qss文件,里面写上qss代码,
然后再在Main里面写上
    QFile qss("*.qss");
    qss.open(QFile::ReadOnly);
    app.setStyleSheet(qss.readAll());
    qss.close();

试试这样能达到你想要的效果嘛?


------解决方案--------------------
对了,你直接在qss按钮里面的样式里面把background-color改成透明就可以了
------解决方案--------------------
pushButton->setStyleSheet("background-color:transparent");
手写的。可能有错误。。
------解决方案--------------------
ui->male_button->setFlat(TRUE);

ui->male_button->setStyleSheet("* { background-color: rgba(0,125,0,0) }");
------解决方案--------------------
引用:
引用:
pushButton->setStyleSheet("background-color:transparent");
手写的。可能有错误。。
试了,不行的。。。

不好意思。少了括号。。
pushButton->setStyleSheet("{background-color:transparent}");
------解决方案--------------------
ui->button->setFlat(true);
ui->button->setStyleSheet("QPushButton{background-image:url(images/aa.png);}");
------解决方案--------------------
如果是继承的使用了qss的话,先用新的qss覆盖以前的设置,然后在pushbutton中设置setWindowFlags(Qt::FramelessWindowHint);setAttribute(Qt::WA_TranslucentBackground);
再到paintevent中进行重画,注意设置笔刷QBrush,记得设置QColor(r,g,b,a),a为透明程度,值0-255这样就可以了