Qt 5.10 Book Examples
LoadMyForm.h
Go to the documentation of this file.
1 // ======================================================================
2 // LoadMyForm.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 <QtUiTools>
15 
16 // ======================================================================
17 class LoadMyForm : public QWidget {
18 Q_OBJECT
19 private:
20  QSlider* m_psld;
21  QLCDNumber* m_plcd;
22 
23 public:
24  LoadMyForm(QWidget* pwgt = 0) : QWidget(pwgt)
25  {
26  QUiLoader* puil = new QUiLoader(this);
27  QFile file(":/MyForm.ui");
28 
29  QWidget* pwgtForm = puil->load(&file);
30  if (pwgtForm) {
31  resize(pwgtForm->size());
32 
33  m_psld = pwgtForm->findChild<QSlider*>("m_sld");
34  m_plcd = pwgtForm->findChild<QLCDNumber*>("m_lcd");
35 
36  QPushButton* pcmdReset =
37  pwgtForm->findChild<QPushButton*>("m_cmdReset");
38  connect(pcmdReset, SIGNAL(clicked()), SLOT(slotReset()));
39 
40  QPushButton* pcmdQuit =
41  pwgtForm->findChild<QPushButton*>("m_cmdQuit");
42  connect(pcmdQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
43 
44  //Layout setup
45  QHBoxLayout* phbxLayout = new QHBoxLayout;
46  phbxLayout->addWidget(pwgtForm);
47  setLayout(phbxLayout);
48  }
49  }
50 
51 public slots:
52  void slotReset()
53  {
54  m_psld->setValue(0);
55  m_plcd->display(0);
56  }
57 };
void slotReset()
Definition: LoadMyForm.h:52
LoadMyForm(QWidget *pwgt=0)
Definition: LoadMyForm.h:24