Qt 5.10 Book Examples
MyApplication.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // MyApplication.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 "MyApplication.h"
13 
14 // ----------------------------------------------------------------------
15 MyApplication::MyApplication(QWidget* pwgt/*= 0*/) : QWidget(pwgt)
16 {
17  QComboBox* pcbo = new QComboBox;
18  QSpinBox* pspb = new QSpinBox;
19  QSlider* psld = new QSlider(Qt::Horizontal);
20  QRadioButton* prad = new QRadioButton("&Radio Button");
21  QCheckBox* pchk = new QCheckBox("&Check Box");
22  QPushButton* pcmd = new QPushButton("&Push Button");
23 
24  pcbo->addItems(QStyleFactory::keys());
25 
26  connect(pcbo,
27  SIGNAL(activated(const QString&)),
28  SLOT(slotChangeStyle(const QString&))
29  );
30 
31  //Layout setup
32  QVBoxLayout* pvbxLayout = new QVBoxLayout;
33  pvbxLayout->addWidget(pcbo);
34  pvbxLayout->addWidget(pspb);
35  pvbxLayout->addWidget(psld);
36  pvbxLayout->addWidget(prad);
37  pvbxLayout->addWidget(pchk);
38  pvbxLayout->addWidget(pcmd);
39  setLayout(pvbxLayout);
40 }
41 
42 // ----------------------------------------------------------------------
43 void MyApplication::slotChangeStyle(const QString& str)
44 {
45  QStyle* pstyle = QStyleFactory::create(str);
46  QApplication::setStyle(pstyle);
47 }
void slotChangeStyle(const QString &str)
MyApplication(QWidget *pwgt=0)