2013-04-23 185 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 
} 

我希望這能幫你。