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

QTableWidget::selectedRanges() returns previous selection instead of current when mouse clicking

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.0
    • None
    • Fedora 32, Qt installed in home via online installer
    • Linux/Wayland

    Description

      QTableWidget::selectedRanges() reports previous selection (or is empty at first click) when mouse clicking to select a cell. This does not happen when using keyboard arrows.

      How to reproduce:

      test.pro

      QT = core gui widgets
      SOURCES = main.cpp
      

      main.cpp

      #include <QApplication>
      #include <QDebug>
      #include <QTableWidget>
      
      int main(int argc, char * argv[])
      {
          QApplication app(argc, argv);
          QTableWidget table(2, 2);
          QObject::connect(&table, &QTableWidget::currentCellChanged, [&] (int, int, int, int)
          {
              auto const ranges = table.selectedRanges();
              if (!ranges.isEmpty())
                  qInfo() << ranges[0].topRow() << ranges[0].leftColumn();
          });
          table.show();
          return app.exec();
      }
      

      Start the program and click on a cell. Nothing is printed. Click on a another cell, the coordinates of the previously selected one are printed.

      Restart the program, this time use arrow keys to select a cell, the right coordinates are instantly printed.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            chnossos Pierre Caissial
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes