Qt 5.10 Book Examples
main.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // main.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 
13 // ----------------------------------------------------------------------
14 QWidget* styledWidget(QStyle* pstyle)
15 {
16  QGroupBox* pgr = new QGroupBox(pstyle->metaObject()->className());
17  QScrollBar* psbr = new QScrollBar(Qt::Horizontal);
18  QCheckBox* pchk = new QCheckBox("&Check Box");
19  QSlider* psld = new QSlider(Qt::Horizontal);
20  QRadioButton* prad = new QRadioButton("&Radio Button");
21  QPushButton* pcmd = new QPushButton("&Push Button");
22 
23  //Layout setup
24  QVBoxLayout* pvbxLayout = new QVBoxLayout;
25  pvbxLayout->addWidget(psbr);
26  pvbxLayout->addWidget(pchk);
27  pvbxLayout->addWidget(psld);
28  pvbxLayout->addWidget(prad);
29  pvbxLayout->addWidget(pcmd);
30  pgr->setLayout(pvbxLayout);
31 
32  QList<QWidget*> pwgtList = pgr->findChildren<QWidget*>();
33  foreach(QWidget* pwgt, pwgtList) {
34  pwgt->setStyle(pstyle);
35  }
36  return pgr;
37 }
38 
39 // ----------------------------------------------------------------------
40 int main(int argc, char** argv)
41 {
42  QApplication app(argc, argv);
43  QWidget wgt;
44 
45  //Layout setup
46  QHBoxLayout* phbxLayout = new QHBoxLayout;
47  foreach (QString str, QStyleFactory::keys()) {
48  phbxLayout->addWidget(styledWidget(QStyleFactory::create(str)));
49  }
50  wgt.setLayout(phbxLayout);
51 
52  wgt.show();
53 
54  return app.exec();
55 }
QWidget * styledWidget(QStyle *pstyle)
Definition: main.cpp:14
int main(int argc, char **argv)
Definition: main.cpp:15