PDA

View Full Version : Can'r find proper signal for QtableView QSqueryModel



cpuinthebrain
1st July 2015, 21:03
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:


QItemSelectionModel *sm = ui->tableView_partners->selectionModel();
connect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)) ,
this, SLOT(enableDeleteButton()));

void Partners::enableDeleteButton()
{

if (ui->tableView_partners->selectionModel()->currentIndex().isValid() == true)
{
ui->pushButton_delete->setEnabled(true);
}

else {
ui->pushButton_delete->setEnabled(false);
}
}

stampede
2nd July 2015, 09:49
You can try connecting directly to your table view's selectionChanged (http://doc.qt.io/qt-5/qabstractitemview.html#selectionChanged) signal.

anda_skoa
2nd July 2015, 10:03
QItemSelectionModel::selectedRows()?

Cheers,
_