QListView with QAbstractListModel shows an empty list

前端 未结 1 1964
时光说笑
时光说笑 2021-01-13 07:00

I have created a very simple example of QListView with a custom QAbstractListModel. The QListView is displayed but it is empty.

相关标签:
1条回答
  • 2021-01-13 07:17

    Your methods data should return "a" only if role = Qt::DisplayRole. Otherwise, it returns "a" for every role.

    So, add a simple test and it will work :

      QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const
    {
        if ( role == Qt::DisplayRole ) {
          return "a";
        }
        return QVariant();
    }
    
    0 讨论(0)
提交回复
热议问题