#include "frmmessagebox.h" #include "ui_frmmessagebox.h" #include "head.h" frmMessageBox *frmMessageBox::self = NULL; frmMessageBox *frmMessageBox::Instance() { if (!self) { static QMutex mutex; QMutexLocker locker(&mutex); if (!self) { self = new frmMessageBox; } } return self; } frmMessageBox::frmMessageBox(QWidget *parent) : QWidget(parent), ui(new Ui::frmMessageBox) { ui->setupUi(this); this->initForm(); } frmMessageBox::~frmMessageBox() { delete ui; } void frmMessageBox::initForm() { this->setWindowOpacity(0.9); this->setProperty("form", true); this->setProperty("canMove", true); this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint); //设置属性以便应用样式表 ui->widgetReturn->setProperty("flag", "return"); } void frmMessageBox::on_btnOk_clicked() { if (ui->btnCancel->isVisible()) { emit result(true); } this->close(); } void frmMessageBox::on_btnCancel_clicked() { emit result(false); this->close(); } void frmMessageBox::showInfo(const QString &msg) { ui->btnOk->setVisible(true); ui->btnCancel->setVisible(false); ui->labInfo->setText(msg); } void frmMessageBox::showQuestion(const QString &msg) { ui->btnOk->setVisible(true); ui->btnCancel->setVisible(true); ui->labInfo->setText(msg); }