#include "CustomMessageDlg.h" #include "ui_CustomMessageDlg.h" CustomMessageDlg::CustomMessageDlg(QWidget *parent) : QDialog(parent) , ui(new Ui::CustomMessageDlg) { ui->setupUi(this); this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Dialog); //setAttribute(Qt::WA_TranslucentBackground); ns_module::ST_BUTTON_DONE butDone = { 1,2,"test",4,"test" }; RunMsgWnd(butDone); } CustomMessageDlg::~CustomMessageDlg() { delete ui; } void CustomMessageDlg::RunMsgWnd(const ns_module::ST_BUTTON_DONE& butDone) { QString str = R"(QLabel { background-image: url()"; switch (butDone.nId) { case ns_module::EN_MSG_WND_ICO::IHINT: str += ":/images/Mess/hint.png"; break; case ns_module::EN_MSG_WND_ICO::IWARN: str += ":/images/Mess/warn.png"; break; case ns_module::EN_MSG_WND_ICO::IERROR: str += ":/images/Mess/error.png"; break; case ns_module::EN_MSG_WND_ICO::IRUN: str += ":/images/Mess/run.png"; break; case ns_module::EN_MSG_WND_ICO::ISTOP: str += ":/images/Mess/stop.png"; break; default: break; } str += R"();})"; ui->errorLogLabel->setStyleSheet(str); ui->tIDlabel_errID->setText(QString::number(butDone.lError)); ui->errorInfoTextEdit->setText(QString::fromLocal8Bit(butDone.strErrMeassage.c_str())); ui->errorDetailsInfoTextEdit->setText(QString::fromLocal8Bit(butDone.strErrMeassage.c_str())); } void CustomMessageDlg::mousePressEvent(QMouseEvent* event) { if(event->button() == Qt::LeftButton && event->pos().y() <= 48) { m_isTitleBarClicked = true; m_dragPosition = event->globalPos() - frameGeometry().topLeft(); event->accept(); } else { m_isTitleBarClicked = false; QDialog::mousePressEvent(event); } } void CustomMessageDlg::mouseMoveEvent(QMouseEvent* event) { if(m_isTitleBarClicked && (event->buttons() & Qt::LeftButton)) { move(event->globalPos() - m_dragPosition); event->accept(); } else { QDialog::mouseMoveEvent(event); } } void CustomMessageDlg::on_tCloseBut_clicked() { on_closeBut_clicked(); // TODO: 都交给它 } void CustomMessageDlg::on_closeBut_clicked() { this->close(); }