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

QItemSelectionModel::select does not select item

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Invalid
    • Affects Version/s: 6.2.3
    • Fix Version/s: None
    • Component/s: Core: Item Models
    • Labels:
      None
    • Environment:
      macOS 12.2
    • Platform/s:
      macOS

      Description

      After updating Qt from 5.15.0 to 6.2.3 selecting an item of a model derived from QItemSelectionModel by ::select (both overloads) seems not to select the item. isSelected and hasSelection, both return false.

      Probably related to https://bugreports.qt.io/browse/QTBUG-93301

      Minimal example to reproduce:

      void BrandPluginViewModel::sayHello()
      {
          qDebug() << "Hello! ";
      }
      
      void BrandPluginViewModel::init()
      {
          // Create selection test model to check if ::select works properly
          QItemSelectionModel* selectionModel = new QItemSelectionModel(m_sourceModel); // m_sourceModel is derived from QAbstractListModel; rowCount is 8 in my case
          QModelIndex modelIndex = m_sourceModel->index(1, 0);
          selectionModel->select(modelIndex, QItemSelectionModel::Select);
          connect(selectionModel, &QItemSelectionModel::selectionChanged, this, &BrandPluginViewModel::sayHello);
          qDebug() << "selectionModel->hasSelection = " << selectionModel->hasSelection(); // prints false
          qDebug() << "selectionModel->isSelected = " << selectionModel->isSelected(modelIndex); // prints false
      }
      

        Attachments

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

          Activity

            People

            Assignee:
            andreasbuhr Andreas Buhr
            Reporter:
            evabetzler Eva Bettina Betzler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes