Doc: Add menu bar to Books example

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ö <topi.reinio@qt.io>
This commit is contained in:
Paul Wicking 2018-06-13 13:04:10 +02:00
parent 06996e1d0e
commit f415f50619
3 changed files with 32 additions and 1 deletions

View File

@ -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("<p>The <b>Books</b> example shows how to use Qt SQL classes "
"with a model/view framework."));
}

View File

@ -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

View File

@ -33,7 +33,7 @@
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Books</string>
<string/>
</property>
<layout class="QVBoxLayout">
<property name="spacing">