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 #include <QtPrintSupport>
15 
16 // ======================================================================
17 class StartDialog : public QWidget {
18 Q_OBJECT
19 public:
20  StartDialog(QWidget* pwgt = 0) : QWidget(pwgt)
21  {
22  QPushButton* pcmdOpenFile = new QPushButton("&OpenFile");
23  connect(pcmdOpenFile,
24  SIGNAL(clicked()),
25  SLOT(slotOpenFileName())
26  );
27 
28  QPushButton* pcmdDirectory = new QPushButton("&Directory");
29  connect(pcmdDirectory,
30  SIGNAL(clicked()),
31  SLOT(slotExistingDirectory())
32  );
33 
34  QPushButton* pcmdColor = new QPushButton("&Color");
35  connect(pcmdColor, SIGNAL(clicked()), SLOT(slotColor()));
36 
37  QPushButton* pcmdPrinter = new QPushButton("&Printer");
38  connect(pcmdPrinter, SIGNAL(clicked()), SLOT(slotPrinter()));
39 
40  QPushButton* pcmdFont = new QPushButton("&Font");
41  connect(pcmdFont, SIGNAL(clicked()), SLOT(slotFont()));
42 
43  QPushButton* pcmdInput = new QPushButton("&Input");
44  connect(pcmdInput, SIGNAL(clicked()), SLOT(slotInput()));
45 
46  QPushButton* pcmdProgress = new QPushButton("P&rogress");
47  connect(pcmdProgress, SIGNAL(clicked()), SLOT(slotProgress()));
48 
49  QVBoxLayout* pvbxLayout = new QVBoxLayout;
50  pvbxLayout->addWidget(pcmdOpenFile);
51  pvbxLayout->addWidget(pcmdDirectory);
52  pvbxLayout->addWidget(pcmdColor);
53  pvbxLayout->addWidget(pcmdPrinter);
54  pvbxLayout->addWidget(pcmdFont);
55  pvbxLayout->addWidget(pcmdInput);
56  pvbxLayout->addWidget(pcmdProgress);
57 
58  setLayout(pvbxLayout);
59  }
60 
61 public slots:
62  // ------------------------------------------------------------------
64  {
65  QString str =
66  QFileDialog::getOpenFileName(0, "Open Dialog", "", "*.cpp *.h");
67  }
68 
69  // ------------------------------------------------------------------
71  {
72  QString str =
73  QFileDialog::getExistingDirectory(0, "Directory Dialog", "");
74  }
75 
76  // ------------------------------------------------------------------
77  void slotPrinter()
78  {
79  QPrinter printer;
80  QPrintDialog* pPrintDialog = new QPrintDialog(&printer);
81  if (pPrintDialog->exec() == QDialog::Accepted) {
82  // Print
83  }
84  delete pPrintDialog;
85  }
86 
87  // ------------------------------------------------------------------
88  void slotColor()
89  {
90  QColor color = QColorDialog::getColor(Qt::blue);
91  qDebug() << color;
92  }
93 
94  // ------------------------------------------------------------------
95  void slotFont()
96  {
97  bool bOk;
98  QFont font = QFontDialog::getFont(&bOk);
99  if (!bOk) {
100  //Cancel was pressed
101  }
102  }
103 
104  // ------------------------------------------------------------------
105  void slotInput()
106  {
107  bool bOk;
108  QString str = QInputDialog::getText(0,
109  "Input",
110  "Name:",
111  QLineEdit::Normal,
112  "Tarja",
113  &bOk
114  );
115  if (!bOk) {
116  // Cancel was pressed
117  }
118  }
119 
120  // ------------------------------------------------------------------
122  {
123  int n = 200000;
124  QProgressDialog* pprd =
125  new QProgressDialog("Processing the data...", "&Cancel", 0, n);
126 
127  pprd->setMinimumDuration(0);
128  pprd->setWindowTitle("Please Wait");
129 
130  for (int i = 0; i < n; ++i) {
131  pprd->setValue(i);
132  qApp->processEvents();
133  if (pprd->wasCanceled()) {
134  break;
135  }
136  }
137  pprd->setValue(n);
138  delete pprd;
139  }
140 
141 };
142 
void slotFont()
Definition: StartDialog.h:95
void slotExistingDirectory()
Definition: StartDialog.h:70
void slotProgress()
Definition: StartDialog.h:121
void slotOpenFileName()
Definition: StartDialog.h:63
void slotPrinter()
Definition: StartDialog.h:77
void slotInput()
Definition: StartDialog.h:105
void slotColor()
Definition: StartDialog.h:88
StartDialog(QWidget *pwgt=0)
Definition: StartDialog.h:20