void CPttMsgBox::disappearInfoWgt(const QString& strConent, const QString& picPath, QWidget* parent)
{
QWidget* myWgt = new QWidget();
QLabel* picLabel = new QLabel(myWgt);;
QSpacerItem* vSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
QGridLayout* gridLayout = new QGridLayout(myWgt);
QLabel* content = new QLabel(myWgt);
myWgt->resize(150, 45);
myWgt->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
myWgt->setWindowOpacity(0.7);
picLabel->setMinimumSize(18, 18);
picLabel->setMaximumSize(picLabel->minimumSize());
content->setText(strConent);
myWgt->setStyleSheet("background-color: rgb(0, 0, 0);color: rgb(255, 255, 255);");
picLabel->setStyleSheet(QString("border-image:url(%1)").arg(picPath));
gridLayout->addWidget(picLabel, 0, 0, 1, 1);
gridLayout->addWidget(content, 0, 1, 1, 1);
gridLayout->addItem(vSpacer, 0, 2, 1, 1);
myWgt->show();
myWgt->activateWindow();
QPoint pos;
if (Q_NULLPTR == parent) {
pos = QApplication::desktop()->geometry().center();
}
else {
pos = parent->geometry().center();
}
myWgt->move(pos - QPoint(myWgt->width() / 2, myWgt->height() / 2));
QTimer* burnTime = new QTimer(myWgt);
burnTime->start(300);
burnTime->setSingleShot(true);
connect(burnTime, &QTimer::timeout, myWgt,
[myWgt]() {
myWgt->setWindowOpacity(0.8);
QTimer* hideTime = new QTimer();
hideTime->start(1200);
hideTime->setSingleShot(true);
connect(hideTime, &QTimer::timeout, myWgt,
[myWgt]() {
delete myWgt;
}
);
});
}
Qt:创建可自动消失的消息提示弹窗(半透明)
最新推荐文章于 2023-04-19 22:11:13 发布