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

QTableWidget: selection/selection mode is quirky

    XMLWordPrintable

Details

    Description

      Consider code below. How selection behaves is rather surprising. When using the keyboard, the selection is cumulative, but the mouse deselects and marks only one cell. Also, calling setCurrentCell() (see keyPressEvent() in code below) discards the current selection.

      -------------------------------------------------------------------------------------------------------------------------
      #include <QtGui/QApplication>
      #include <QtGui/QTableWidget>
      #include <QtDebug>

      class MyTable : public QTableWidget
      {
      Q_OBJECT

      public:
      MyTable(int numRows, int numCols) : QTableWidget(numRows, numCols)

      { setSelectionMode(QAbstractItemView::ContiguousSelection); setFocusPolicy(Qt::StrongFocus); }

      virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &, const QEvent *ev = 0) const

      { Q_UNUSED(ev); return QItemSelectionModel::SelectCurrent; }

      void keyPressEvent(QKeyEvent *event)

      { QTableWidget::keyPressEvent(event); static int counter = 0; if (++counter == 10) setCurrentCell(rowCount() - 1, columnCount() - 1); qDebug() << counter << ". key pressed" << endl; }

      };

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

      MyTable table(8, 3);
      table.resize(500, 500);

      table.show();

      return app.exec();
      }

      #include "main.moc"
      -------------------------------------------------------------------------------------------------------------------------

      Attachments

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

        Activity

          People

            monsen Marius Bugge Monsen
            fenglich Frans Englich (closed Nokia identity)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes