querydialog.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "querydialog.h"
  2. #include <QPushButton>
  3. #include <QDebug>
  4. QueryDialog::QueryDialog(QObject *parent) :
  5. QObject(parent)
  6. {
  7. m_acceptButtonText = tr("Yes");
  8. m_rejectButtonText = tr("No");
  9. }
  10. void QueryDialog::open() {
  11. m_icon.load(this->m_icon_path);
  12. mbox.setWindowTitle(this->m_titleText);
  13. mbox.setText(this->m_message);
  14. mbox.setIconPixmap(m_icon);
  15. const QString yes(m_acceptButtonText);
  16. const QString no(m_rejectButtonText);
  17. QPushButton *acceptButton = mbox.addButton(yes, QMessageBox::AcceptRole);
  18. QPushButton *rejectButton = mbox.addButton(no, QMessageBox::RejectRole);
  19. //QPushButton *rejectButton = mbox.addButton(QMessageBox::Abort);
  20. mbox.exec();
  21. if (mbox.clickedButton() == acceptButton) {
  22. qDebug()<< ">>>>>yes";
  23. emit accepted();
  24. } else if (mbox.clickedButton() == rejectButton) {
  25. qDebug()<< ">>>>>>no";
  26. emit rejected();
  27. }
  28. }
  29. QString QueryDialog::text(){
  30. return this->m_message;
  31. }
  32. void QueryDialog::setText(QString value){
  33. this->m_message = value;
  34. }
  35. QString QueryDialog::titleText(){
  36. return m_titleText;
  37. }
  38. void QueryDialog::setTitleText(QString value){
  39. this->m_titleText = value;
  40. }
  41. QString QueryDialog::icon(){
  42. return this->m_icon_path;
  43. }
  44. void QueryDialog::setIcon(QString value){
  45. this->m_icon_path = value;
  46. }
  47. QString QueryDialog::acceptButtonText(){
  48. return this->m_acceptButtonText;
  49. }
  50. void QueryDialog::setAcceptButtonText(QString value){
  51. this->m_acceptButtonText = value;
  52. }
  53. QString QueryDialog::rejectButtonText(){
  54. return m_rejectButtonText;
  55. }
  56. void QueryDialog::setRejectButtonText(QString value){
  57. this->m_rejectButtonText = value;
  58. }