直接附上效果图
满足以下条件
1、在QDialog窗口代码中添加以下语句:
setWindowFlags(Qt::FramelessWindowHint);//取消标题栏
setAttribute(Qt::WA_TranslucentBackground);//使透明效果生效
2、如果你该程序是在嵌入式端运行的话,需要有GPU,然后在运行的时候执行在EGLFS模式下,这样圆弧形提示框才生效,否者setAttribute(Qt::WA_TranslucentBackground);指令不生效。
代码实例
statement::statement(QDialog *parent)
: QDialog(parent)
{
initUi();
}
void statement::initUi()
{
this->resize(480,260);
this->setObjectName("stateObject");
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
QLabel *tilteLabel = new QLabel("相关信息");
QLabel *cpuLabel = new QLabel("CPU:xxxxxxx");
QLabel *ubootLabel = new QLabel("uboot:2016.01");
QLabel *kernelLabel = new QLabel("kernel版本:xxxxx");
QLabel *authorLabel =new QLabel("作者:HYB");
QLabel *appLabel = new QLabel("程序版本:1.0.3");
QLabel *netLabel =new QLabel("了解更多:https://blog.csdn.net/qq_45147279");
QLabel *nameLabel = new QLabel("@Qt学习专栏");
QWidget *infoFrame = new QWidget;
infoFrame->setObjectName("infoFrame");
QPushButton *retBtn = new QPushButton(this);
retBtn->setFocusPolicy(Qt::NoFocus);
retBtn->setStyleSheet("background-color: #2e2e2e;border:none;");
retBtn->setIcon(QIcon(":/pic/maindesktop/Retlogo.png"));
retBtn->setIconSize(QSize(40,40));
QHBoxLayout *hLayout = new QHBoxLayout;
QSpacerItem *hSpacer2 = new QSpacerItem(60, 1280,
QSizePolicy::Expanding,
QSizePolicy::Maximum);
hLayout->addSpacerItem(hSpacer2);
hLayout->addWidget(retBtn);
QVBoxLayout *infoLayout = new QVBoxLayout;
infoLayout->addWidget(cpuLabel,1);
infoLayout->addWidget(ubootLabel,1);
infoLayout->addWidget(kernelLabel,1);
infoLayout->addWidget(authorLabel,1);
infoLayout->addWidget(appLabel,1);
infoLayout->addWidget(netLabel,1);
infoLayout->addSpacing(10);
infoLayout->addWidget(nameLabel,2);
infoFrame->setLayout(infoLayout);
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(tilteLabel,1);
vLayout->addWidget(infoFrame,6);
vLayout->addLayout(hLayout,1);
vLayout->setContentsMargins(40,40,30,10);
QWidget *frame = new QWidget;
frame->setObjectName("externframe");
frame->setLayout(vLayout);
QVBoxLayout *vLayout1 = new QVBoxLayout;
vLayout1->addWidget(frame);
vLayout1->setMargin(0);
this->setLayout(vLayout1);
connect(retBtn, &QPushButton::clicked,[=]{this->close();});
}
#qss样式
QWidget#infoFrame{
background: #16181c;
border-radius:20;
}
QWidget#externframe{
background: #2f2f2f;
border-radius:20;
border: solid 5px #ffffff;
}