使用qss在也是这样,由于使用了WA_TranslucentBackground属性,模态的情况下背景透明处就是黑漆漆一片
基本情况就像这样
#include "dialog.h"
Dialog::Dialog(QWidget *parent) : QDialog(parent)
{
resize(500, 500);
this->setAttribute(Qt::WA_TranslucentBackground);
this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);
m_pbtnShow = new QPushButton(this);
m_pbtnShow->setGeometry(20, 20, 100, 30);
m_pbtnShow->setText("Show");
m_pdlgTest = new QDialog(this);
m_pdlgTest->setAttribute(Qt::WA_TranslucentBackground);
m_pdlgTest->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);
m_pdlgTest->resize(300, 300);
QPushButton * pbtnTemp = new QPushButton(m_pdlgTest);
pbtnTemp->setGeometry(50, 50, 100, 30);
m_pdlgTest->setStyleSheet("QDialog{background-color: transparent;}");
connect(m_pbtnShow, SIGNAL(clicked()), this, SLOT(onbtnClickShowDialog()));
}
Dialog::~Dialog()
{
}
void Dialog::onbtnClickShowDialog()
{
m_pdlgTest->exec();
}