I have subclassed QTableView and inside of it there are 8x8 (64) cells. Now, I am trying to reimplement selectionChanged() slot. Here is declaration:
protected slots:
void selectionChanged(const QItemSelection& selected,
const QItemSelection& deselected);
protected slots:
void selectionChanged(const QItemSelection& selected,
const QItemSelection& deselected);
To copy to clipboard, switch view to plain text mode
and here is implementation:
void CTableView::selectionChanged(const QItemSelection& selected,
const QItemSelection& deselected)
{
// qDebug() << "\nBEGIN\nSelected cell:" << selected.indexes() <<
// "\nDeselected cell:" << deselected.indexes() <<
// "\nCurrently selected cells (history):" << this->selectionModel()->selectedIndexes() <<
// "\nEND\n";
selected.indexes())
{
// qDebug() << "\nmodelIndex.row():" <<
// modelIndex.row() <<
// "\n";
qDebug() << "\nthis->selectionModel()->selectedColumns(modelIndex.row()):" <<
this->selectionModel()->selectedColumns(modelIndex.row()) <<
"\n";
// if(this->selectionModel()->selectedColumns(modelIndex.row()).size()<=0)
// {
// qDebug() << "\nOnly one cell selected:\n" <<
// this->selectionModel()->selectedColumns(modelIndex.row()).size() <<
// "\n";
// }
// else
// {
// qDebug() << "\nMore than one cell selected\n";
// }
}
}
void CTableView::selectionChanged(const QItemSelection& selected,
const QItemSelection& deselected)
{
// qDebug() << "\nBEGIN\nSelected cell:" << selected.indexes() <<
// "\nDeselected cell:" << deselected.indexes() <<
// "\nCurrently selected cells (history):" << this->selectionModel()->selectedIndexes() <<
// "\nEND\n";
foreach(QModelIndex modelIndex,
selected.indexes())
{
// qDebug() << "\nmodelIndex.row():" <<
// modelIndex.row() <<
// "\n";
qDebug() << "\nthis->selectionModel()->selectedColumns(modelIndex.row()):" <<
this->selectionModel()->selectedColumns(modelIndex.row()) <<
"\n";
// if(this->selectionModel()->selectedColumns(modelIndex.row()).size()<=0)
// {
// qDebug() << "\nOnly one cell selected:\n" <<
// this->selectionModel()->selectedColumns(modelIndex.row()).size() <<
// "\n";
// }
// else
// {
// qDebug() << "\nMore than one cell selected\n";
// }
}
}
To copy to clipboard, switch view to plain text mode
When I click on some cell, the slot is launched, but
this->selectionModel()->selectedColumns(modelIndex.row())
this->selectionModel()->selectedColumns(modelIndex.row())
To copy to clipboard, switch view to plain text mode
returns empty list:
this->selectionModel()->selectedColumns(modelIndex.row()): ()
Why??selectedColumnsEmpty.jpgAs you can see from screenshot, I've selected a cell, but selectedColumns() list is empty.
Bookmarks