Message_box.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef MESSAGE_BOX_H
  2. #define MESSAGE_BOX_H
  3. #include <QMessageBox>
  4. #include <QDialogButtonBox>
  5. #include <QGridLayout>
  6. #include "custom_window.h"
  7. class QLabel;
  8. class MessageBox : public CustomWindow
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit MessageBox(QWidget *parent = 0, const QString &title = tr("Tip"), const QString &text = "",
  13. QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::Ok);
  14. ~MessageBox();
  15. QAbstractButton *clickedButton() const;
  16. QMessageBox::StandardButton standardButton(QAbstractButton *button) const;
  17. // 设置默认按钮
  18. void setDefaultButton(QPushButton *button);
  19. void setDefaultButton(QMessageBox::StandardButton button);
  20. // 设置窗体标题
  21. void setTitle(const QString &title);
  22. // 设置提示信息
  23. void setText(const QString &text);
  24. // 设置窗体图标
  25. void setIcon(const QString &icon);
  26. // 添加控件-替换提示信息所在的QLabel
  27. void addWidget(QWidget *pWidget);
  28. protected:
  29. // 多语言翻译
  30. void changeEvent(QEvent *event);
  31. private slots:
  32. void onButtonClicked(QAbstractButton *button);
  33. private:
  34. void translateUI();
  35. int execReturnCode(QAbstractButton *button);
  36. private:
  37. QLabel *m_pIconLabel;
  38. QLabel *m_pLabel;
  39. QGridLayout *m_pGridLayout;
  40. QDialogButtonBox *m_pButtonBox;
  41. QAbstractButton *m_pClickedButton;
  42. QAbstractButton *m_pDefaultButton;
  43. };
  44. #endif // MESSAGE_BOX_H