QMessageBox的icon跟随主题优化
This commit is contained in:
parent
1185dbc62b
commit
236880855b
|
@ -23,17 +23,29 @@ void MyMessageBox::setThemeIcon(const QString& themeIcon)
|
||||||
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::themeIconChanged, this, &MyMessageBox::on_themeIconChanged);
|
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()
|
void MyMessageBox::on_themeIconChanged()
|
||||||
{
|
{
|
||||||
QIcon titleIcon = QIcon::fromTheme(m_themeIcon, QIcon(":/images/yhkylin-backup-tools.png"));
|
QIcon titleIcon = QIcon::fromTheme(m_themeIcon, QIcon(":/images/yhkylin-backup-tools.png"));
|
||||||
setWindowIcon(titleIcon);
|
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)
|
void MessageBoxUtils::QMESSAGE_BOX_INFORMATION(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
|
||||||
{
|
{
|
||||||
MyMessageBox *box = new MyMessageBox(q_parent);
|
MyMessageBox *box = new MyMessageBox(q_parent);
|
||||||
|
|
||||||
box->setIcon(QMessageBox::Information);
|
box->setMsgIcon(QMessageBox::Information);
|
||||||
box->setWindowTitle(typelabel);
|
box->setWindowTitle(typelabel);
|
||||||
box->setText(message);
|
box->setText(message);
|
||||||
box->setStandardButtons(QMessageBox::Ok);
|
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);
|
MyMessageBox *box = new MyMessageBox(q_parent);
|
||||||
|
|
||||||
box->setIcon(QMessageBox::Warning);
|
box->setMsgIcon(QMessageBox::Warning);
|
||||||
box->setWindowTitle(typelabel);
|
box->setWindowTitle(typelabel);
|
||||||
box->setText(message);
|
box->setText(message);
|
||||||
box->setStandardButtons(QMessageBox::Ok);
|
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);
|
MyMessageBox *box = new MyMessageBox(q_parent);
|
||||||
|
|
||||||
box->setIcon(QMessageBox::Question);
|
box->setMsgIcon(QMessageBox::Question);
|
||||||
box->setWindowTitle(typelabel);
|
box->setWindowTitle(typelabel);
|
||||||
box->setText(message);
|
box->setText(message);
|
||||||
box->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
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)
|
void MessageBoxUtils::QMESSAGE_BOX_CRITICAL(QWidget* q_parent, const QString& typelabel, const QString& message, const QString& label)
|
||||||
{
|
{
|
||||||
MyMessageBox *box = new MyMessageBox(q_parent);
|
MyMessageBox *box = new MyMessageBox(q_parent);
|
||||||
box->setIcon(QMessageBox::Critical);
|
box->setMsgIcon(QMessageBox::Critical);
|
||||||
box->setWindowTitle(typelabel);
|
box->setWindowTitle(typelabel);
|
||||||
box->setText(message);
|
box->setText(message);
|
||||||
box->setStandardButtons(QMessageBox::Ok);
|
box->setStandardButtons(QMessageBox::Ok);
|
||||||
|
|
|
@ -13,12 +13,15 @@ public:
|
||||||
virtual ~MyMessageBox();
|
virtual ~MyMessageBox();
|
||||||
|
|
||||||
void setThemeIcon(const QString& themeIcon);
|
void setThemeIcon(const QString& themeIcon);
|
||||||
|
void setMsgIcon(QMessageBox::Icon icon);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void on_themeIconChanged();
|
void on_themeIconChanged();
|
||||||
|
void on_iconChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_themeIcon;
|
QString m_themeIcon;
|
||||||
|
QMessageBox::Icon m_icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MessageBoxUtils
|
class MessageBoxUtils
|
||||||
|
|
Loading…
Reference in New Issue