Qt 5.10 Book Examples
SDIProgram.h
Go to the documentation of this file.
1 // ======================================================================
2 // SDIProgram.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 "DocWindow.h"
15 
16 // ======================================================================
17 class SDIProgram : public QMainWindow {
18 Q_OBJECT
19 public:
20  SDIProgram(QWidget* pwgt = 0) : QMainWindow(pwgt)
21  {
22  QMenu* pmnuFile = new QMenu("&File");
23  QMenu* pmnuHelp = new QMenu("&Help");
24  DocWindow* pdoc = new DocWindow;
25 
26  pmnuFile->addAction("&Open...",
27  pdoc,
28  SLOT(slotLoad()),
29  QKeySequence("CTRL+O")
30  );
31  pmnuFile->addAction("&Save",
32  pdoc,
33  SLOT(slotSave()),
34  QKeySequence("CTRL+S")
35  );
36  pmnuFile->addAction("S&ave As...",
37  pdoc,
38  SLOT(slotSaveAs())
39  );
40  pmnuFile->addSeparator();
41  pmnuFile->addAction("&Quit",
42  qApp,
43  SLOT(quit()),
44  QKeySequence("CTRL+Q")
45  );
46  pmnuHelp->addAction("&About",
47  this,
48  SLOT(slotAbout()),
49  Qt::Key_F1
50  );
51 
52  menuBar()->addMenu(pmnuFile);
53  menuBar()->addMenu(pmnuHelp);
54 
55  setCentralWidget(pdoc);
56  connect(pdoc,
57  SIGNAL(changeWindowTitle(const QString&)),
58  SLOT(slotChangeWindowTitle(const QString&))
59  );
60 
61  statusBar()->showMessage("Ready", 2000);
62  }
63 
64 public slots:
65  void slotAbout()
66  {
67  QMessageBox::about(this, "Application", "SDI Example");
68  }
69 
70  void slotChangeWindowTitle(const QString& str)
71  {
72  setWindowTitle(str);
73  }
74 };
SDIProgram(QWidget *pwgt=0)
Definition: SDIProgram.h:20
void slotChangeWindowTitle(const QString &str)
Definition: SDIProgram.h:70
void slotAbout()
Definition: SDIProgram.h:65