QMessageBox的icon跟随主题优化

This commit is contained in:
赵民勇 2022-08-25 17:19:32 +08:00
parent 1185dbc62b
commit 236880855b
2 changed files with 19 additions and 4 deletions

View File

@ -23,17 +23,29 @@ void MyMessageBox::setThemeIcon(const QString& themeIcon)
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_themeIconChanged);
}
void MyMessageBox::setMsgIcon(QMessageBox::Icon icon) {
m_icon = icon;
on_iconChanged();
disconnect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_iconChanged);
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_iconChanged);
}
void MyMessageBox::on_themeIconChanged()
{
QIcon titleIcon = QIcon::fromTheme(m_themeIcon, QIcon(":/images/yhkylin-backup-tools.png"));
setWindowIcon(titleIcon);
}
void MyMessageBox::on_iconChanged()
{
setIcon(m_icon);
}
void MessageBoxUtils::QMESSAGE_BOX_INFORMATION(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
{
MyMessageBox *box = new MyMessageBox(q_parent);
box->setIcon(QMessageBox::Information);
box->setMsgIcon(QMessageBox::Information);
box->setWindowTitle(typelabel);
box->setText(message);
box->setStandardButtons(QMessageBox::Ok);
@ -46,7 +58,7 @@ void MessageBoxUtils::QMESSAGE_BOX_WARNING(QWidget* q_parent, const QString& typ
{
MyMessageBox *box = new MyMessageBox(q_parent);
box->setIcon(QMessageBox::Warning);
box->setMsgIcon(QMessageBox::Warning);
box->setWindowTitle(typelabel);
box->setText(message);
box->setStandardButtons(QMessageBox::Ok);
@ -59,7 +71,7 @@ bool MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(QWidget *q_parent, const QStri
{
MyMessageBox *box = new MyMessageBox(q_parent);
box->setIcon(QMessageBox::Question);
box->setMsgIcon(QMessageBox::Question);
box->setWindowTitle(typelabel);
box->setText(message);
box->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
@ -77,7 +89,7 @@ bool MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(QWidget *q_parent, const QStri
void MessageBoxUtils::QMESSAGE_BOX_CRITICAL(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
{
MyMessageBox *box = new MyMessageBox(q_parent);
box->setIcon(QMessageBox::Critical);
box->setMsgIcon(QMessageBox::Critical);
box->setWindowTitle(typelabel);
box->setText(message);
box->setStandardButtons(QMessageBox::Ok);

View File

@ -13,12 +13,15 @@ public:
virtual ~MyMessageBox();
void setThemeIcon(const QString& themeIcon);
void setMsgIcon(QMessageBox::Icon icon);
public slots:
void on_themeIconChanged();
void on_iconChanged();
private:
QString m_themeIcon;
QMessageBox::Icon m_icon;
};
class MessageBoxUtils