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

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2
    • Core: Item Models
    • None
    • Windows x64 Visual Studio 2019
    • 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

            dfaure_kdab David Faure
            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