QtableView how to find the proper signal
-
@SGaist
The problem is that hasSelection() is a method, i need a signal.Now i can use only currentRowChanged(), but it doesn't emit when nothing is selected.I need every time when the table has selected row to be possible to delete and when there is no selection to be not possible. -
You can connect to
selectionChanged()
signal and useselectedRows()
inside the connected slot to check if any row is selected. -
i did this
connect(ui->tableView_partners->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(enableDeleteButton()));
void Partners::enableDeleteButton()
{if (ui->tableView_partners->selectionModel()->selectedRows().isEmpty()) { ui->pushButton_delete->setEnabled(false); } else { ui->pushButton_delete->setEnabled(true); }
}
Unfortunately it works until new row is added.When a row is added there is no selected index in the tableView, but the button is enabled.Probably after adding row tableView selection is empty, but the model by default has last row selected or something like this.
Is it possible aways to have selected rows?Any ideas? -
Do you mean enableDeleteButton is not called if you add a new row to the table ?
-
So adding a new row clears the current selection and this doesn't result in your slot being called ? Sounds like it could be a little bug.
Can you reproduce this with a minimal compilable example ?
-
Here is the link to the example: Example
What i want to achieve is when there is no selected row the button to be disabled.It works, but when select row and click add (adding new record) the button remain enabled, but no row is selected.Another option that i don't prefer is the view to have always selected row. -
I'm not fluent in Russian at all, I only saw the publicities. Where's the download ?
-
Sorry for the late reply, the page says that there's nothing to be found