1 Attachment(s)
QTableWidget: Strange row selection after changing item while sorting is enabled
Hi guys,
i have a QTableWidget with a few (in my case 5) columns and following properties:
- Select Row
- Sorting Enabled
When the table is sorted in the first column and I change the content an item of the first column, the row changes to the new position in the sorting order but the selection for some rows stays on the same row number as before. (see picture)
Attachment 11104
After a few tests with different column numbers I saw, that only the first and the last column selection will change. When I click on any item, the selection goes to the normal behavior.
Does somebody have the idea to fix the problem?
Thanks,
Tobi
Re: QTableWidget: Strange row selection after changing item while sorting is enabled
Please provide a minimal compilable example reproducing the problem.
Re: QTableWidget: Strange row selection after changing item while sorting is enabled
Hi,
here is a minimal example that produces the described issue. Btw I'm using Qt 5.4.1.
main.cpp
Code:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTableWidget>
{
Q_OBJECT
public:
~MainWindow();
private:
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
setFixedSize(550,200);
// Setup Table
table->setColumnCount(5);
table->setRowCount(5);
table->setSortingEnabled(true);
// filling the table
for(int i=0; i<table->rowCount(); i++)
// sort table
table->sortByColumn(0,Qt::AscendingOrder);
// Add table to window widget
setCentralWidget(table);
}
MainWindow::~MainWindow()
{
delete table;
}
When I change the number in the first cell from 1 to 6 I got the selection problem.
Re: QTableWidget: Strange row selection after changing item while sorting is enabled
I think it is a bug.
I tried to change other column and row data randomly the app crashes with this message
Quote:
ASSERT failure in QPersistentModelIndex::~QPersistentModelIndex: "persistent model indexes corrupted", file itemmodels\qabstractitemmodel.cpp, line 556