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

Problem deleting or inserting rows in a QTableWidget with column spans

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 4.6.0
    • 4.5.0
    • Widgets: Itemviews
    • None
    • 0d51611fa524091ddca3c6c11edb0eae8ffe3b02

      The problem is that when you have a QTableWidget table that contains one or more rows with multiple column spans and you try to delete or insert a row before the row with the column span, the table will fail to shift the spanned row up (if deleting a row) or down (if inserting a new row). The contents of the row
      will get shifted correctly, but not the column span. Qt3 did not have this problem.

      Here is some code that shows the problem:

      #include <QtGui/QtGui>

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

      int ROWS = 10;
      int COLS = 10;

      //create empty 10x10 table
      QTableWidget table(ROWS, COLS);
      for (int i=0; i<ROWS; i++)

      { for (int j=0; j<COLS; j++) table.setItem(i, j, new QTableWidgetItem("")); }

      //set multiple column span and text for row #5 (i.e., row index = 4)
      int row = 4;
      int col = 0;
      int ROWSPAN = 1;
      table.setSpan(row, col, ROWSPAN, COLS);
      table.item(row, col)->setText("This is a multiple column span ...");

      //Delete first row to unveil the problem.
      //After deleting the first row, row #4 (and not row #5) should contain the multiple column span.
      table.removeRow(0);

      table.show();
      return app.exec();
      }

      Expected to see:
      I expected to see row #4 (not row #5) displayed as a multiple column span row.

      Got instead:
      Instead I got a table with row #5 displayed as a multiple column span row.
      The problem is that the QTableWidget class does not account for a change in
      the number of rows, when it happens above a row that contains a multiple
      column span. The text of the spanned row gets shifted correctly, but not the
      column span itself.

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

            dedietri Gabriel de Dietrich (drgvond)
            janichol Andy Nichols
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes