Qt实现窗口半透明显示

一、效果图

1、主界面

2、子界面

二、代码

  
      //①设置界面基本颜色
    this->setAutoFillBackground(true);//属性控制小部件背景是否自动填充
    QPalette palette = this->palette();
    palette.setColor(QPalette::Base,QColor(0,0,0,255));//alpha 0~255;0为不透明,255为透明
    palette.setColor(QPalette::Window,QColor(0,0,0,100));//alpha 0~255;0为不透明,255为透明
    this->setPalette(palette);
//这样设置就可以了,但是我的需求是窗体要有边框,故需要添加下边一步

    //②使用样式变添加边框,设置透明背景
ui->tableWidget->setStyleSheet(QString("border-width: 2px;"\ "border-style: solid;"\ "border-radius:15px;"\ "border-color: rgb(255,255,255);"\ "background-color:transparent;"));

猜你喜欢

转载自www.cnblogs.com/shuoguoleilei/p/13203654.html