McL*_*Lan 7 c++ qt model qtableview
我有一个QTableView
正常工作在GUI上显示我的模型.但是,我想创建一个"SIGNAL/SLOT",当我从中选择一行时,它可以工作QTableView
.
我怎样才能做到这一点?
您可以通过以下方式进行操作:
connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
SLOT(slotSelectionChange(const QItemSelection &, const QItemSelection &))
);
Run Code Online (Sandbox Code Playgroud)
插槽将是:
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
}
Run Code Online (Sandbox Code Playgroud)
希望对您有所帮助。