diff --git a/examples/widgets/doc/src/addressbook.qdoc b/examples/widgets/doc/src/addressbook.qdoc index cd7cd09f5b..1fa0bfa9d4 100644 --- a/examples/widgets/doc/src/addressbook.qdoc +++ b/examples/widgets/doc/src/addressbook.qdoc @@ -220,11 +220,12 @@ The QItemSelectionModel class provides a \l{QItemSelectionModel::selectionChanged()}{selectionChanged} signal that is connected to \c{AddressWidget}'s - \c selectionChanged() signal. This signal to signal connection - is necessary to enable the \uicontrol{Edit Entry...} and - \uicontrol{Remove Entry} actions in \c MainWindow's Tools menu. This - connection is further explained in \c MainWindow's - implementation. + \c selectionChanged() signal. We also connect + QTabWidget::currentChanged() signal to the lambda expression which + emits \c{AddressWidget}'s \c selectionChanged() as well. These + connections are necessary to enable the \uicontrol{Edit Entry...} and + \uicontrol{Remove Entry} actions in \c MainWindow's Tools menu. + It is further explained in \c MainWindow's implementation. Each table view in the address book is added as a tab to the QTabWidget with the relevant label, obtained from the QStringList diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp index 9480d2ca8e..143f6266dd 100644 --- a/examples/widgets/itemviews/addressbook/addresswidget.cpp +++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp @@ -192,6 +192,12 @@ void AddressWidget::setupTabs() &QItemSelectionModel::selectionChanged, this, &AddressWidget::selectionChanged); + connect(this, &QTabWidget::currentChanged, this, [this](int tabIndex) { + auto *tableView = qobject_cast(widget(tabIndex)); + if (tableView) + emit selectionChanged(tableView->selectionModel()->selection()); + }); + addTab(tableView, str); } }