Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.0
-
None
-
d45c0d3930e295e9798f9172fa0f151044f7036b
Description
In the following example the selectionChanged signal will be emitted when switching between Item 2 and Item 3 even though the selection is not changing.
main.cpp
#include <QtGui> class Output : public QObject { Q_OBJECT public slots: void selectionChanged(QItemSelection selected, QItemSelection deselected) { qDebug() << "selectionChanged"; qDebug() << "selected:"; foreach(QModelIndex index, selected.indexes()) qDebug() << index.row() << index.column(); qDebug() << "deselected:"; foreach(QModelIndex index, deselected.indexes()) qDebug() << index.row() << index.column(); } }; #include "main.moc" int main(int argc, char *argv[]) { QApplication a(argc, argv); QStandardItemModel *pModel = new QStandardItemModel(1, 4); pModel->setData(pModel->index(0, 0), "Item 1"); pModel->setData(pModel->index(0, 1), "Item 2"); pModel->setData(pModel->index(0, 2), "Item 3"); pModel->setData(pModel->index(0, 3), "Item 4"); if(QStandardItem *pItem = pModel->item(0, 1)) { pItem->setFlags(pItem->flags() ^ (Qt::ItemIsSelectable | Qt::ItemIsEditable)); pModel->setItem(0, 1, pItem); } if(QStandardItem *pItem = pModel->item(0, 2)) { pItem->setFlags(Qt::ItemIsEnabled); pModel->setItem(0, 2, pItem); } if(QStandardItem *pItem = pModel->item(0, 3)) { pItem->setFlags(0); pModel->setItem(0, 3, pItem); } QTableView *pTableView = new QTableView(0); pTableView->setModel(pModel); pTableView->show(); Output output; output.connect(pTableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(selectionChanged(QItemSelection,QItemSelection))); return a.exec(); }