Qt 5.10 Book Examples
StartDialog.h
Go to the documentation of this file.
1 // ======================================================================
2 // StartDialog.h
3 // ======================================================================
4 // This file is a part of the book
5 // "Qt 5.10 Professional programming with C++"
6 // http://qt-book.com
7 // ======================================================================
8 // Copyright (c) 2017 by Max Schlee
9 // ======================================================================
10 
11 #pragma once
12 
13 #include <QtWidgets>
14 
15 // ======================================================================
16 class StartDialog : public QWidget {
17 Q_OBJECT
18 public:
19  StartDialog(QWidget* pwgt = 0) : QWidget(pwgt)
20  {
21  QPushButton* pcmdMessage = new QPushButton("&Message");
22  connect(pcmdMessage, SIGNAL(clicked()), SLOT(slotMessage()));
23 
24  QPushButton* pcmdInformation = new QPushButton("&Information");
25  connect(pcmdInformation, SIGNAL(clicked()), SLOT(slotInformation()));
26 
27  QPushButton* pcmdWarning = new QPushButton("&Warning");
28  connect(pcmdWarning, SIGNAL(clicked()), SLOT(slotWarning()));
29 
30  QPushButton* pcmdCritical = new QPushButton("&Critical");
31  connect(pcmdCritical, SIGNAL(clicked()), SLOT(slotCritical()));
32 
33  QPushButton* pcmdAbout = new QPushButton("&About");
34  connect(pcmdAbout, SIGNAL(clicked()), SLOT(slotAbout()));
35 
36  QPushButton* pcmdAboutQt = new QPushButton("A&boutQt");
37  connect(pcmdAboutQt, SIGNAL(clicked()), SLOT(slotAboutQt()));
38 
39  QPushButton* pcmdError = new QPushButton("&Error");
40  connect(pcmdError, SIGNAL(clicked()), SLOT(slotError()));
41 
42  QVBoxLayout* pvbxLayout = new QVBoxLayout;
43  pvbxLayout->addWidget(pcmdMessage);
44  pvbxLayout->addWidget(pcmdInformation);
45  pvbxLayout->addWidget(pcmdWarning);
46  pvbxLayout->addWidget(pcmdCritical);
47  pvbxLayout->addWidget(pcmdAbout);
48  pvbxLayout->addWidget(pcmdAboutQt);
49  pvbxLayout->addWidget(pcmdError);
50 
51  setLayout(pvbxLayout);
52  }
53 
54 public slots:
55  // ------------------------------------------------------------------
56  void slotMessage()
57  {
58  QMessageBox* pmbx =
59  new QMessageBox("MessageBox",
60  "<b>A</b> <i>Simple</i> <u>Message</u>",
61  QMessageBox::Question,
62  QMessageBox::Yes,
63  QMessageBox::No,
64  QMessageBox::Cancel | QMessageBox::Escape
65  );
66  int n = pmbx->exec();
67  delete pmbx;
68 
69  if (n == QMessageBox::Yes) {
70  // Yes button was pressed
71  }
72  }
73 
74  // ------------------------------------------------------------------
76  {
77  QMessageBox::information(0, "Information", "Operation Complete");
78  }
79 
80  // ------------------------------------------------------------------
81  void slotWarning()
82  {
83  int n =
84  QMessageBox::warning(0,
85  "Warning" ,
86  "The text in the file has changed,"
87  "\n Do you want to save the changes?",
88  "Yes",
89  "No",
90  QString(),
91  0,
92  1
93  );
94  if (!n) {
95  // Saving the changes!
96  }
97  }
98 
99  // ------------------------------------------------------------------
101  {
102  int n =
103  QMessageBox::critical(0,
104  "Attention",
105  "This operation will make your "
106  "computer unusable, continue?",
107  QMessageBox::Yes | QMessageBox::Default,
108  QMessageBox::No,
109  QMessageBox::Cancel | QMessageBox::Escape
110  );
111  if (n == QMessageBox::Yes) {
112  // Do it!
113  }
114  }
115 
116  // ------------------------------------------------------------------
117  void slotAbout()
118  {
119  QMessageBox::about(0, "About", "My Program Ver. 1.0");
120  }
121 
122  // ------------------------------------------------------------------
123  void slotAboutQt()
124  {
125  QMessageBox::aboutQt(0);
126  }
127 
128  // ------------------------------------------------------------------
129  void slotError()
130  {
131  (new QErrorMessage(this))->showMessage("Write Error");
132  }
133 };
134 
void slotCritical()
Definition: StartDialog.h:100
void slotAbout()
Definition: StartDialog.h:117
void slotAboutQt()
Definition: StartDialog.h:123
void slotMessage()
Definition: StartDialog.h:56
void slotError()
Definition: StartDialog.h:129
void slotWarning()
Definition: StartDialog.h:81
void slotInformation()
Definition: StartDialog.h:75
StartDialog(QWidget *pwgt=0)
Definition: StartDialog.h:19