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

QTableWidget selection bug

    XMLWordPrintable

Details

    Description

      This example demonstrates a bug in QTable.*

      The intention is that the table automatically expands on selection/currentChanged. E.g. if you select a cell in the last row another one should be added. This part works fine.

      The strangeness starts when you drag the mouse back up. Somehow the cells stay selected. This is not the way selection works in the rest of the table.

      To reproduce:

      run app
      click and drag a selection from top left corner to cell 3, 3
      drag cursor to cell 2,2. Notice that cell 3, 3 2,3 and 3,2 gets unselected.

      Now click and drag a selection from top left to bottom left, you'll notice that a row was added. Now drag the mouse back to 1.1 Notice that cells 2,1 3,1 4,1 etc stay selected.

      #include <QtGui>

      class Table : public QTableWidget
      {
      Q_OBJECT
      public:
      Table(QWidget *parent = 0)
      : QTableWidget(5, 5, parent)

      { #if 0 // this seems to exhibit the same problems connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(onSelectionChanged())); #endif }

      virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
      {
      QTableWidget::currentChanged(current, previous);
      if (current.row() == rowCount() - 1)

      { insertRow(rowCount()); }

      }
      #if 0 // this seems to exhibit the same problems
      public slots:
      void onSelectionChanged()
      {
      foreach(const QModelIndex &ind, selectionModel()->selectedIndexes()) {
      if (ind.row() == rowCount() - 1)

      { insertRow(rowCount()); break; }

      }
      }
      #endif
      };

      #include "main.moc"

      int main(int argc, char **argv)
      {
      QApplication a(argc, argv);
      Table table;
      table.show();
      a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
      return a.exec();
      }

      Attachments

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

        Activity

          People

            vfm Thierry Bastian (closed Nokia identity) (Inactive)
            rve Anders Bakken
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes