Qt 5.10 Book Examples
InputDialog.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // InputDialog.cpp
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 #include <QtWidgets>
12 #include "InputDialog.h"
13 
14 // ----------------------------------------------------------------------
15 InputDialog::InputDialog(QWidget* pwgt/*= 0*/)
16  : QDialog(pwgt, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
17 {
18  m_ptxtFirstName = new QLineEdit;
19  m_ptxtLastName = new QLineEdit;
20 
21  QLabel* plblFirstName = new QLabel("&First Name");
22  QLabel* plblLastName = new QLabel("&Last Name");
23 
24  plblFirstName->setBuddy(m_ptxtFirstName);
25  plblLastName->setBuddy(m_ptxtLastName);
26 
27  QPushButton* pcmdOk = new QPushButton("&Ok");
28  QPushButton* pcmdCancel = new QPushButton("&Cancel");
29 
30  connect(pcmdOk, SIGNAL(clicked()), SLOT(accept()));
31  connect(pcmdCancel, SIGNAL(clicked()), SLOT(reject()));
32 
33  //Layout setup
34  QGridLayout* ptopLayout = new QGridLayout;
35  ptopLayout->addWidget(plblFirstName, 0, 0);
36  ptopLayout->addWidget(plblLastName, 1, 0);
37  ptopLayout->addWidget(m_ptxtFirstName, 0, 1);
38  ptopLayout->addWidget(m_ptxtLastName, 1, 1);
39  ptopLayout->addWidget(pcmdOk, 2,0);
40  ptopLayout->addWidget(pcmdCancel, 2, 1);
41  setLayout(ptopLayout);
42 }
43 
44 // ----------------------------------------------------------------------
45 QString InputDialog::firstName() const
46 {
47  return m_ptxtFirstName->text();
48 }
49 
50 // ----------------------------------------------------------------------
51 QString InputDialog::lastName() const
52 {
53  return m_ptxtLastName->text();
54 }
QString firstName() const
Definition: InputDialog.cpp:45
QString lastName() const
Definition: InputDialog.cpp:51
InputDialog(QWidget *pwgt=0)
Definition: InputDialog.cpp:15