Make sure table widget shortcuts do not affect other parts of the UI

When handling the Ctrl+Space and Shift+Space keyboard shortcuts in
ExtenededTableWidget, make sure to not do anything if there is 1) no
table selection, or 2) if the table widget has no focus.

See issue #2038.
This commit is contained in:
Martin Kleusberg
2019-11-07 17:29:42 +01:00
parent 15051ed0ee
commit 58beba0b3f

View File

@@ -384,10 +384,14 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
// Add spreadsheet shortcuts for selecting entire columns or entire rows.
QShortcut* selectColumnShortcut = new QShortcut(QKeySequence("Ctrl+Space"), this);
connect(selectColumnShortcut, &QShortcut::activated, [this]() {
if(!hasFocus() || selectionModel()->selectedIndexes().isEmpty())
return;
selectionModel()->select(QItemSelection(selectionModel()->selectedIndexes().first(), selectionModel()->selectedIndexes().last()), QItemSelectionModel::Select | QItemSelectionModel::Columns);
});
QShortcut* selectRowShortcut = new QShortcut(QKeySequence("Shift+Space"), this);
connect(selectRowShortcut, &QShortcut::activated, [this]() {
if(!hasFocus() || selectionModel()->selectedIndexes().isEmpty())
return;
selectionModel()->select(QItemSelection(selectionModel()->selectedIndexes().first(), selectionModel()->selectedIndexes().last()), QItemSelectionModel::Select | QItemSelectionModel::Rows);
});