QTableView: select rows don't work correctly
-
Hello,
I have a class named ObjectTableView which extends QTableView. The constructor:
@ ObjectTableView::ObjectTableView(QWidget *parent) :
QTableView(parent)
{
objectsListModel = new QStandardItemModel(0, 2, this);
objectsListModel->setHorizontalHeaderItem(0, new QStandardItem("Object Name"));
objectsListModel->setHorizontalHeaderItem(1, new QStandardItem("Mesh File"));
setModel(objectsListModel);horizontalHeader()->setSectionResizeMode(0, QHeaderView::Interactive);
horizontalHeader()->setSectionResizeMode(1, QHeaderView::Interactive);
horizontalHeader()->resizeSection(0, 90);
horizontalHeader()->resizeSection(1, 230);
verticalHeader()->hide();setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows); //don't work ?
}@Here the method which allow me to add an element to the table:
@ void ObjectTableView::addObject(const SceneObject *sceneObject)
{
QStandardItem *itemObjectName = new QStandardItem(QString::fromStdString(sceneObject->getName()));
itemObjectName->setData(qVariantFromValue(sceneObject), Qt::UserRole + 1);
itemObjectName->setEditable(false);QStandardItem *itemMeshFile = new QStandardItem(QString::fromStdString(sceneObject->getModel()->getMeshes()->getMeshFilename()));
itemMeshFile->setData(qVariantFromValue(sceneObject), Qt::UserRole + 1);
itemMeshFile->setEditable(false);int nextRow = objectsListModel->rowCount();
objectsListModel->insertRow(nextRow);
objectsListModel->setItem(nextRow, 0, itemObjectName);
objectsListModel->setItem(nextRow, 1, itemMeshFile);resizeRowsToContents();
}@Problem: the selection behavior by rows don't work correctly. Here an example when I select a row and then the next one:
"https://drive.google.com/file/d/0B7DcxH-qq_HTUkk1NTRaMmUyVUE/view?usp=sharing":https://drive.google.com/file/d/0B7DcxH-qq_HTUkk1NTRaMmUyVUE/view?usp=sharingWhat is wrong in my source code ?
Thank you in advance.
-
Difficult to check like this. How about sharing the complete sample code which gives this problem ? I can look at the output & respond back.