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

In QListWidget, when an item is selected, the selection model returns empty index set

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.2
    • Fix Version/s: None
    • Component/s: Core: Item Models
    • Labels:
      None
    • Environment:
      Windows x64 Visual Studio 2019
    • Platform/s:
      Windows

      Description

      In a delegate for items in a QlistWidget, in the paint call, I am obtaining the selection model.  The index is selected, however, selectedIndexes returns empty.

       

       

      void AlbumDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
      {
          auto selectionModel = _album->selectionModel();
          bool isSelected = selectionModel->isSelected(index);
          if (isSelected)
          {
              QModelIndexList indexes = selectionModel->selectedIndexes();
               // the list 'indices' is returning empty
          }
      }
      

       

      Setup:

       

      class AlbumList : public QListWidget
      {
          Q_OBJECT
      public:
          explicit AlbumList(QWidget *parent = nullptr);
          ~AlbumList();    AlbumItem *itemFromIndex(const QModelIndex &index) const;
      };
      
      class Album : public QFrame
      {
          Q_OBJECT
      public:
          .
          .
          .
          AlbumList *_albumList;
      };
      
      class AlbumDelegate : public QStyledItemDelegate
      {    Q_OBJECT
      public:
          explicit AlbumDelegate(Album *parent, bool checkable);
          ~AlbumDelegate();    
      
      protected:
          void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
          QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &index) const;
      
      private:  
          Album *_album;
      };
      
      
      Album::Album(QWidget *parent) : QFrame(parent), ui(new Ui::Album)
      {
          ui->setupUi(this);
          _albumList = ui->albumList;    
          _delegate = new AlbumDelegate(this, true);
          _albumList->setItemDelegate(_delegate);
      
      }

       

       

        Attachments

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

          Activity

            People

            Assignee:
            dfaure_kdab David Faure
            Reporter:
            doug_rogers Doug Rogers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes