Address Book example: Correctly update "Edit entry" and "Remove entry" actions
They are not updated after switching tabs. Thus they can be enabled even when no entry is selected: select an entry on the current tab and then switch to an empty tab. Emit AddressWidget::selectionChanged() signal after changing the current tab to update these actions. Change-Id: I00da15ed6c3d3839210ae3ffbe1436e234695522 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
82c787ec3b
commit
c181f418b9
@ -220,11 +220,12 @@
|
|||||||
The QItemSelectionModel class provides a
|
The QItemSelectionModel class provides a
|
||||||
\l{QItemSelectionModel::selectionChanged()}{selectionChanged}
|
\l{QItemSelectionModel::selectionChanged()}{selectionChanged}
|
||||||
signal that is connected to \c{AddressWidget}'s
|
signal that is connected to \c{AddressWidget}'s
|
||||||
\c selectionChanged() signal. This signal to signal connection
|
\c selectionChanged() signal. We also connect
|
||||||
is necessary to enable the \uicontrol{Edit Entry...} and
|
QTabWidget::currentChanged() signal to the lambda expression which
|
||||||
\uicontrol{Remove Entry} actions in \c MainWindow's Tools menu. This
|
emits \c{AddressWidget}'s \c selectionChanged() as well. These
|
||||||
connection is further explained in \c MainWindow's
|
connections are necessary to enable the \uicontrol{Edit Entry...} and
|
||||||
implementation.
|
\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
|
Each table view in the address book is added as a tab to the
|
||||||
QTabWidget with the relevant label, obtained from the QStringList
|
QTabWidget with the relevant label, obtained from the QStringList
|
||||||
|
@ -192,6 +192,12 @@ void AddressWidget::setupTabs()
|
|||||||
&QItemSelectionModel::selectionChanged,
|
&QItemSelectionModel::selectionChanged,
|
||||||
this, &AddressWidget::selectionChanged);
|
this, &AddressWidget::selectionChanged);
|
||||||
|
|
||||||
|
connect(this, &QTabWidget::currentChanged, this, [this](int tabIndex) {
|
||||||
|
auto *tableView = qobject_cast<QTableView *>(widget(tabIndex));
|
||||||
|
if (tableView)
|
||||||
|
emit selectionChanged(tableView->selectionModel()->selection());
|
||||||
|
});
|
||||||
|
|
||||||
addTab(tableView, str);
|
addTab(tableView, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user