I have a QTableView
which is working properly showing my model on the GUI. however, I would like to create a "SIGNAL/SLOT" that works when I select a row from the QTableView
.
How can I do that?
I have a QTableView
which is working properly showing my model on the GUI. however, I would like to create a "SIGNAL/SLOT" that works when I select a row from the QTableView
.
How can I do that?
You can do it in this way:
connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
SLOT(slotSelectionChange(const QItemSelection &, const QItemSelection &))
);
And the slot would be:
void MainWindow::slotSelectionChange(const QItemSelection &, const QItemSelection &)
{
QModelIndexList selection = ui->tableView->selectionModel()->selectedRows();//Here you are getting the indexes of the selected rows
//Now you can create your code using this information
}
I hope this can help you.
Use the currentRowChanged(const QModelIndex & current, const QModelIndex & previous)
signal from the selection model (docs).
See the documentation QAbstractItemView https://qt-project.org/doc/qt-4.7/qabstractitemview.html
void QAbstractItemView activated (const QModelIndex &index ) [signal]
This signal is emitted when the item specified by index is activated by the user. How to activate items depends on the platform; e.g., by single- or double-clicking the item, or by pressing the Return or Enter key when the item is current.
And use QModelIndex::row()
© 2022 - 2024 — McMap. All rights reserved.