2013-04-23 37 views

Trả lời

2

Sử dụng tín hiệu currentRowChanged(const QModelIndex & current, const QModelIndex & previous) từ mô hình lựa chọn (docs).

2

Xem QAbstractItemView tài liệu https://qt-project.org/doc/qt-4.7/qabstractitemview.html

trống QAbstractItemView kích hoạt (const QModelIndex & index) [tín hiệu]

Tín hiệu này được phát ra khi mục theo quy định của chỉ số được kích hoạt bởi người sử dụng. Cách kích hoạt các mục phụ thuộc vào nền tảng; ví dụ: bằng cách nhấp một lần hoặc nhấp đúp vào mục hoặc bằng cách nhấn phím Quay lại hoặc Nhập khi mục đó hiện tại.

Và sử dụng QModelIndex :: hàng()

+1

Kích hoạt không giống như lựa chọn. – cmannett85

3

Bạn có thể làm điều đó theo cách này:

connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), 
      SLOT(slotSelectionChange(const QItemSelection &, const QItemSelection &)) 
      ); 

Và khe sẽ là:

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 
} 

Tôi hy vọng điều này có thể giúp bạn.

Các vấn đề liên quan