#include "StyledMessageBox.h" #include void StyledMessageBox::information(QWidget* parent, const QString& title, const QString& text) { QMessageBox msgBox(parent); msgBox.setWindowTitle(title); msgBox.setText(text); msgBox.setIcon(QMessageBox::Information); applyStyle(msgBox); setChineseButtonText(msgBox); // 直接设置所有按钮的样式 QList buttonList = msgBox.buttons(); for (QAbstractButton* button : buttonList) { button->setStyleSheet("QPushButton { background-color: #404040; color: white; border: 1px solid #666666; padding: 5px; font-size: 14pt; } " "QPushButton:hover { background-color: #505050; }"); } msgBox.exec(); } void StyledMessageBox::warning(QWidget* parent, const QString& title, const QString& text) { QMessageBox msgBox(parent); msgBox.setWindowTitle(title); msgBox.setText(text); msgBox.setIcon(QMessageBox::Warning); applyStyle(msgBox); setChineseButtonText(msgBox); // 直接设置所有按钮的样式 QList buttonList = msgBox.buttons(); for (QAbstractButton* button : buttonList) { button->setStyleSheet("QPushButton { background-color: #404040; color: white; border: 1px solid #666666; padding: 5px; font-size: 14pt; } " "QPushButton:hover { background-color: #505050; }"); } msgBox.exec(); } void StyledMessageBox::critical(QWidget* parent, const QString& title, const QString& text) { QMessageBox msgBox(parent); msgBox.setWindowTitle(title); msgBox.setText(text); msgBox.setIcon(QMessageBox::Critical); applyStyle(msgBox); setChineseButtonText(msgBox); // 直接设置所有按钮的样式 QList buttonList = msgBox.buttons(); for (QAbstractButton* button : buttonList) { button->setStyleSheet("QPushButton { background-color: #404040; color: white; border: 1px solid #666666; padding: 5px; font-size: 14pt; } " "QPushButton:hover { background-color: #505050; }"); } msgBox.exec(); } QMessageBox::StandardButton StyledMessageBox::question(QWidget* parent, const QString& title, const QString& text, QMessageBox::StandardButtons buttons) { QMessageBox msgBox(parent); msgBox.setWindowTitle(title); msgBox.setText(text); msgBox.setIcon(QMessageBox::Question); msgBox.setStandardButtons(buttons); applyStyle(msgBox); setChineseButtonText(msgBox); // 直接设置所有按钮的样式 QList buttonList = msgBox.buttons(); for (QAbstractButton* button : buttonList) { button->setStyleSheet("QPushButton { background-color: #404040; color: white; border: 1px solid #666666; padding: 5px; font-size: 14pt; } " "QPushButton:hover { background-color: #505050; }"); } return (QMessageBox::StandardButton)msgBox.exec(); } void StyledMessageBox::applyStyle(QMessageBox& msgBox) { msgBox.setStyleSheet("QMessageBox { background-color: #25262A; color: black; font-size: 16pt; } " "QMessageBox QLabel { color: white; background-color: transparent; font-size: 16pt; } " "QMessageBox QPushButton { background-color: #404040; color: white; border: 1px solid #666666; padding: 5px; font-size: 14pt; } " "QMessageBox QPushButton:hover { background-color: #505050; } " "QMessageBox .QLabel { font-size: 16pt; } " "QMessageBox::title { font-size: 16pt; color: black; } " "QMessageBox::icon { background-color: transparent; }"); } void StyledMessageBox::setChineseButtonText(QMessageBox& msgBox) { msgBox.setButtonText(QMessageBox::Ok, "确定"); msgBox.setButtonText(QMessageBox::Yes, "确定"); msgBox.setButtonText(QMessageBox::No, "取消"); }