Qt 5.10 Book Examples
HelpBrowser.h
Go to the documentation of this file.
1 // ======================================================================
2 // HelpBrowser.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 
15 // ======================================================================
16 class HelpBrowser : public QWidget {
17  Q_OBJECT
18 
19 public:
20  HelpBrowser(const QString& strPath,
21  const QString& strFileName,
22  QWidget* pwgt = 0
23  ) : QWidget(pwgt)
24  {
25  QPushButton* pcmdBack = new QPushButton("<<");
26  QPushButton* pcmdHome = new QPushButton("Home");
27  QPushButton* pcmdForward = new QPushButton(">>");
28  QTextBrowser* ptxtBrowser = new QTextBrowser;
29 
30  connect(pcmdBack, SIGNAL(clicked()),
31  ptxtBrowser, SLOT(backward())
32  );
33  connect(pcmdHome, SIGNAL(clicked()),
34  ptxtBrowser, SLOT(home())
35  );
36  connect(pcmdForward, SIGNAL(clicked()),
37  ptxtBrowser, SLOT(forward())
38  );
39  connect(ptxtBrowser, SIGNAL(backwardAvailable(bool)),
40  pcmdBack, SLOT(setEnabled(bool))
41  );
42  connect(ptxtBrowser, SIGNAL(forwardAvailable(bool)),
43  pcmdForward, SLOT(setEnabled(bool))
44  );
45 
46  ptxtBrowser->setSearchPaths(QStringList() << strPath);
47  ptxtBrowser->setSource(QString(strFileName));
48 
49  //Layout setup
50  QVBoxLayout* pvbxLayout = new QVBoxLayout;
51  QHBoxLayout* phbxLayout = new QHBoxLayout;
52  phbxLayout->addWidget(pcmdBack);
53  phbxLayout->addWidget(pcmdHome);
54  phbxLayout->addWidget(pcmdForward);
55  pvbxLayout->addLayout(phbxLayout);
56  pvbxLayout->addWidget(ptxtBrowser);
57  setLayout(pvbxLayout);
58  }
59 };
60 
HelpBrowser(const QString &strPath, const QString &strFileName, QWidget *pwgt=0)
Definition: HelpBrowser.h:20