I have QtablewView used with QSqlQueryModel.
I want when a row is selected to make "remove" button enabled.When no selection is there the button to remain disabled.

I figured out how to get signal when the selection has changed, but i need whether there is a selected row:

Qt Code:
  1. QItemSelectionModel *sm = ui->tableView_partners->selectionModel();
  2. connect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
  3. this, SLOT(enableDeleteButton()));
  4.  
  5. void Partners::enableDeleteButton()
  6. {
  7.  
  8. if (ui->tableView_partners->selectionModel()->currentIndex().isValid() == true)
  9. {
  10. ui->pushButton_delete->setEnabled(true);
  11. }
  12.  
  13. else {
  14. ui->pushButton_delete->setEnabled(false);
  15. }
  16. }
To copy to clipboard, switch view to plain text mode