Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
5.7.1, 5.11.1
-
None
Description
Hi !
With a QTableWidget and sorting enabled, when you clear/add content successively the data displayed by the widget are incorrect ; it is illustrated with the snapshot joined to this ticket.
The bug ( ? ) exists with both Linux and Windows 10, and the code provided below shows it.
To generate the wrong display, you will have to click:
- 3 times on the second column
- 2 times on the first
- 1 one the second
Well, it is at least the way for me to do it; the main idea is to play with the sorting of the columns.
Here is the snipped code that reproduce the problem
#include <QApplication> #include <QTableWidget> #include <QHeaderView> int main(int argc, char *argv[]) { QApplication a(argc, argv); QTableWidget w; for(int i = 0 ; i < 3 ; i++) { w.insertColumn(i); w.setHorizontalHeaderItem(i, new QTableWidgetItem(QString("Col %1").arg(i))); } w.setSortingEnabled(true); w.sortByColumn(2, Qt::DescendingOrder); QObject::connect(w.horizontalHeader(), &QHeaderView::sectionPressed, [&]() { static int a = 0; if (a++ % 2 == 0) { w.clearContents(); w.setRowCount(0); } else { for(int i = 0 ; i < 3; i++) { w.insertRow(i); for(int j = 0 ; j < 3 ; j++) w.setItem(i, j, new QTableWidgetItem(QString("%1x%2").arg(i).arg(j))); } } }); w.show(); return a.exec(); }