70 lines
2.3 KiB
C++
70 lines
2.3 KiB
C++
#include "StyledMessageBox.h"
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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: black; 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, "确定");
|
|
} |