From f415f50619ceedff05bcf97336cf05374130a2a7 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Wed, 13 Jun 2018 13:04:10 +0200 Subject: Doc: Add menu bar to Books example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add menu bar with Help->About that contains a short description of the example application. Remove redundant title string between menu and application content. Task-number: QTBUG-68652 Change-Id: I31fb386ab9c01eff86b8ed3ef274ba8cfdb0148b Reviewed-by: Topi Reiniƶ --- examples/sql/books/bookwindow.cpp | 26 ++++++++++++++++++++++++++ examples/sql/books/bookwindow.h | 5 +++++ examples/sql/books/bookwindow.ui | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/sql/books/bookwindow.cpp b/examples/sql/books/bookwindow.cpp index 3aac5b55b7..76f3c9da8f 100644 --- a/examples/sql/books/bookwindow.cpp +++ b/examples/sql/books/bookwindow.cpp @@ -136,6 +136,7 @@ BookWindow::BookWindow() ); ui.bookTable->setCurrentIndex(model->index(0, 0)); + createMenuBar(); } void BookWindow::showError(const QSqlError &err) @@ -143,3 +144,28 @@ void BookWindow::showError(const QSqlError &err) QMessageBox::critical(this, "Unable to initialize Database", "Error initializing database: " + err.text()); } + +void BookWindow::createMenuBar() +{ + QAction *quitAction = new QAction(tr("&Quit"), this); + QAction *aboutAction = new QAction(tr("&About"), this); + QAction *aboutQtAction = new QAction(tr("&About Qt"), this); + + QMenu *fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(quitAction); + + QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAction); + helpMenu->addAction(aboutQtAction); + + connect(quitAction, &QAction::triggered, this, &BookWindow::close); + connect(aboutAction, &QAction::triggered, this, &BookWindow::about); + connect(aboutQtAction, &QAction::triggered, qApp, &QApplication::aboutQt); +} + +void BookWindow::about() +{ + QMessageBox::about(this, tr("About Books"), + tr("

The Books example shows how to use Qt SQL classes " + "with a model/view framework.")); +} diff --git a/examples/sql/books/bookwindow.h b/examples/sql/books/bookwindow.h index 4b2be0e729..ec6b935242 100644 --- a/examples/sql/books/bookwindow.h +++ b/examples/sql/books/bookwindow.h @@ -63,11 +63,16 @@ class BookWindow: public QMainWindow public: BookWindow(); +private slots: + void about(); + private: void showError(const QSqlError &err); Ui::BookWindow ui; QSqlRelationalTableModel *model; int authorIdx, genreIdx; + + void createMenuBar(); }; #endif diff --git a/examples/sql/books/bookwindow.ui b/examples/sql/books/bookwindow.ui index c81a86cb2c..ce8f9f933a 100644 --- a/examples/sql/books/bookwindow.ui +++ b/examples/sql/books/bookwindow.ui @@ -33,7 +33,7 @@ - Books + -- cgit v1.2.3