我有一个QTableView
,它能够正常地在GUI上显示我的模型。但是,我想创建一个“SIGNAL/SLOT”,当我从QTableView
中选择一行时,它能够正常工作。
我该如何做到这一点?
我有一个QTableView
,它能够正常地在GUI上显示我的模型。但是,我想创建一个“SIGNAL/SLOT”,当我从QTableView
中选择一行时,它能够正常工作。
我该如何做到这一点?
connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
SLOT(slotSelectionChange(const QItemSelection &, const QItemSelection &))
);
而插槽将会是:
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
}
我希望这能帮助到你。
使用选择模型(文档)的currentRowChanged(const QModelIndex & current, const QModelIndex & previous)
信号。