2013-04-23 189 views

回答

2

使用选择模型中的currentRowChanged(const QModelIndex & current, const QModelIndex & previous)信号(docs)。

2

参见文档QAbstractItemView中https://qt-project.org/doc/qt-4.7/qabstractitemview.html

空隙QAbstractItemView中激活(常量QModelIndex &指数)信号]

当由索引指定的项目被激活 由用户这个信号被发射。如何激活项目取决于平台;例如通过 单击或双击该项目,或通过按回车键或当项目最新时按回车键。

并使用QModelIndex ::行()

+1

激活与选择不同。 – cmannett85 2013-04-23 16:08:16

3

你能做到这样:

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 
} 

我希望这能帮你。