I have a QTableView inside a QTabWidgetwhere i enter new row with 6 columns everytime i press a button. Out of 6 columns, 3 columns have QPushButton set on them. I need the row number of the clicked button from the QTableView. I have connected the QPushButton clicked signal to my slot clickedIndex()
This is how i am trying to get the row index of the clicked button but the list is empty.
QModelIndex TabView::clickedIndex()
{
//get the list of currently selected indexes from the model
QModelIndexList indexList = m_ui->tableView->selectionModel()->selectedIndexes();
if(!indexList.isEmpty())
{
//usually the list should contain only one index at a time
return indexList.front();
}
}
I also tried connecting pressed signal from QTableView but the slot is never called.
connect(m_ui->tableView, &QTableView::pressed, this, &TabView::clickedIndex);
I believe if there is a QWidget on one of the cells in a QTableView model the slot is never called. When i click on cells which do not carry a button the connection works.
I need:
I just need the QModelIndex to the clicked button in the model.
Note: i am using Qt 5.7.1 and i have found some bug reports related to selectedIndexes() like this
Is there a workaround for this?
Aucun commentaire:
Enregistrer un commentaire