增加通讯协议
This commit is contained in:
+50
-20
@@ -15,47 +15,56 @@ ConfirmDialog::ConfirmDialog(QWidget* parent)
|
||||
if (parent) setGeometry(parent->rect());
|
||||
setStyleSheet("background-color: rgba(0,0,0,102);");
|
||||
|
||||
QWidget* panel = new QWidget(this);
|
||||
panel->setObjectName("ConfirmPanel");
|
||||
panel->setFixedSize(560, 260);
|
||||
panel->setStyleSheet(QString(
|
||||
m_panel = new QWidget(this);
|
||||
m_panel->setObjectName("ConfirmPanel");
|
||||
m_panel->setFixedSize(700, 420);
|
||||
m_panel->setStyleSheet(QString(
|
||||
"QWidget#ConfirmPanel{background-color:%1;border:2px solid %2;border-radius:16px;}")
|
||||
.arg(C::PANEL, C::BORDER));
|
||||
|
||||
QVBoxLayout* lay = new QVBoxLayout(panel);
|
||||
QVBoxLayout* lay = new QVBoxLayout(m_panel);
|
||||
lay->setContentsMargins(28, 24, 28, 24);
|
||||
lay->setSpacing(16);
|
||||
lay->setSpacing(0); // 标题与正文不留间隙(与“操作说明”弹窗一致)
|
||||
|
||||
m_title = new QLabel("", panel);
|
||||
m_title->setStyleSheet(QString("color:%1;font-size:28px;font-weight:700;").arg(C::TEXT));
|
||||
m_title = new QLabel("", m_panel);
|
||||
m_title->setStyleSheet(QString("background:transparent;color:%1;font-size:50px;font-weight:700;").arg(C::TEXT));
|
||||
m_title->setAlignment(Qt::AlignCenter);
|
||||
lay->addWidget(m_title);
|
||||
lay->addSpacing(60); // 标题与正文之间空一行
|
||||
|
||||
m_body = new QLabel("", panel);
|
||||
m_body->setStyleSheet(QString("color:%1;font-size:22px;").arg(C::TEXT));
|
||||
m_body = new QLabel("", m_panel);
|
||||
m_body->setStyleSheet(QString("background:transparent;color:%1;font-size:50px;").arg(C::TEXT));
|
||||
m_body->setAlignment(Qt::AlignCenter);
|
||||
m_body->setWordWrap(true);
|
||||
lay->addWidget(m_body, 1);
|
||||
lay->addWidget(m_body); // 不再拉伸:标题与正文紧挨着
|
||||
lay->addStretch(1); // 剩余空间放在正文与按钮之间(标题/正文保持自然高度,标题顶到最上面)
|
||||
|
||||
QHBoxLayout* btnLay = new QHBoxLayout();
|
||||
btnLay->addStretch(1);
|
||||
QPushButton* ok = new QPushButton("确认", panel);
|
||||
ok->setProperty("variant", "primary");
|
||||
ok->setFixedSize(160, 72);
|
||||
QPushButton* ok = new QPushButton("确认", m_panel);
|
||||
// 常态灰底、选中(悬停/焦点)蓝底白字。
|
||||
// 注意:该表设了 background-color,会压住全局的 variant/焦点规则,所以状态必须写在这里。
|
||||
ok->setFixedSize(180, 80);
|
||||
ok->setStyleSheet(QString(
|
||||
"QPushButton{background-color:%1;color:%2;border:1px solid %3;border-radius:12px;font-size:60px;}"
|
||||
"QPushButton:hover,QPushButton:focus{background-color:%4;color:#FFFFFF;border:2px solid #8ABFFF;}")
|
||||
.arg(C::PANEL_HI, C::TEXT, C::BORDER, C::PRIMARY));
|
||||
connect(ok, &QPushButton::clicked, this, &ConfirmDialog::accept);
|
||||
QPushButton* cancel = new QPushButton("取消", panel);
|
||||
cancel->setFixedSize(160, 72);
|
||||
cancel->setStyleSheet(cancelButtonStyle(40)); // 选中时红底白字
|
||||
connect(cancel, &QPushButton::clicked, this, &ConfirmDialog::reject);
|
||||
m_cancel = new QPushButton("取消", m_panel);
|
||||
m_cancel->setFixedSize(180, 80); // 与“确认”同尺寸
|
||||
m_cancel->setStyleSheet(cancelButtonStyle(60)); // 与“确认”同字号;选中时红底白字
|
||||
connect(m_cancel, &QPushButton::clicked, this, &ConfirmDialog::reject);
|
||||
btnLay->addWidget(ok);
|
||||
btnLay->addWidget(cancel);
|
||||
btnLay->addSpacing(80); // “确认”与“取消”之间留 40px
|
||||
btnLay->addWidget(m_cancel);
|
||||
btnLay->addStretch(1);
|
||||
lay->addSpacing(30); // 正文与按钮之间留 30px
|
||||
lay->addLayout(btnLay);
|
||||
|
||||
QVBoxLayout* root = new QVBoxLayout(this);
|
||||
root->setContentsMargins(0, 0, 0, 0);
|
||||
root->addStretch(1);
|
||||
root->addWidget(panel, 0, Qt::AlignHCenter);
|
||||
root->addWidget(m_panel, 0, Qt::AlignHCenter);
|
||||
root->addStretch(1);
|
||||
}
|
||||
|
||||
@@ -70,6 +79,27 @@ bool ConfirmDialog::confirm(QWidget* parent, const QString& title, const QString
|
||||
return dlg.exec() == QDialog::Accepted;
|
||||
}
|
||||
|
||||
void ConfirmDialog::message(QWidget* parent, const QString& title, const QString& text)
|
||||
{
|
||||
ConfirmDialog dlg(parent);
|
||||
dlg.m_panel->setFixedSize(900, 600); // 正文行数少 → 面板收窄
|
||||
dlg.m_cancel->hide(); // 只保留“确认”
|
||||
dlg.m_title->setStyleSheet(QString("background:transparent;color:%1;font-size:50px;font-weight:700;").arg(C::TEXT));
|
||||
dlg.m_body->setStyleSheet(QString("background:transparent;color:%1;font-size:50px;").arg(C::TEXT));
|
||||
dlg.m_title->setWordWrap(true);
|
||||
dlg.m_title->setContentsMargins(0, 20, 0, 0); // 标题文字距该行顶部 10px
|
||||
dlg.m_body->setContentsMargins(0, 0, 0, 0);
|
||||
dlg.m_body->setAlignment(Qt::AlignCenter); // 正文居中(水平+垂直)
|
||||
if (QBoxLayout* lay = qobject_cast<QBoxLayout*>(dlg.m_panel->layout())) {
|
||||
lay->setSpacing(0); // 统一间隔置 0,各段间距单独控制
|
||||
lay->setContentsMargins(28, 28, 28, 28); // 内容距面板四边 28px
|
||||
//lay->insertSpacing(lay->count() - 1, 20); // “确认”按钮上方留 20px
|
||||
}
|
||||
dlg.setTitle(title);
|
||||
dlg.setText(text);
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
void ConfirmDialog::toast(QWidget* parent, const QString& text, int ms)
|
||||
{
|
||||
QDialog* d = new QDialog(parent);
|
||||
|
||||
Reference in New Issue
Block a user