Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-69610

With a QTableWidget and sorting enabled on a column, clearing and setting data display wrong content

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.7.1, 5.11.1
    • None
    • Linux/X11, Windows

    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();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            lem__mel Majid EL IDRISSI
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes