Hello together I'm experimenting with qt and have some questions about this whole
Model-Delegate-Proxy stuff.

What I want to achieve is to show a list of Persons in a QListView, with the ability of
filtering, and showing letter-captions, (Like many List-Controls on mobileOS) and writing the whole information for a person in 1 cell.

-----------------------
|A |
-----------------------
|Abigail Familly-Name |
|Audrey Familly-Name |
-----------------------
|C |
-----------------------
|Christian Familly-Name|
-----------------------
|D |
-----------------------
|Daniel Familly-Name |
-----------------------

I have a Class: Person where I have the structure of the information (Name,Famillyname,day of b.... aso.)

On the MODEL side I have a QAbstractListModel
Qt Code:
  1. ..........
  2. explicit PersonModel(QObject *parent = 0);
  3.  
  4. int columnCount(const QModelIndex &parent) const;
  5. int rowCount( const QModelIndex &index = QModelIndex()) const;
  6.  
  7. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  8. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
  9. void FillData();
  10.  
  11. private:
  12. Q_DISABLE_COPY(PersonModel);
  13. QList<Person*> Persons;
  14. ...............
To copy to clipboard, switch view to plain text mode 
My data() function looks like this:
Qt Code:
  1. QVariant PersonModel::data(const QModelIndex &index, int role) const
  2. {
  3. if (role == Qt::DisplayRole)
  4. {
  5. qRegisterMetaType<Person>("Person");
  6. v.setValue<CPerson>(*Persons.at(index.row()));
  7. return v;
  8. }
  9. return QVariant();
  10. }
To copy to clipboard, switch view to plain text mode 
Since I want to write different parts of the person class in on cell I return the
whole structure in a QVariant.

On the DELEGATE side my paint looks like this:
Qt Code:
  1. void PersonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
  2. {
  3. if (index.column() == 0) {
  4. Person entry =index.model()->data(index).value<Person>();
  5. painter->setFont( QFont("Arial",14,QFont::Bold));
  6. QRect NameRect = option.rect;
  7. NameRect.setLeft(5);
  8. painter->drawText(NameRect,Qt::AlignLeft,entry.GetName());
  9. NameRect.setLeft(0);
  10. NameRect.setRight(NameRect.width()-5);
  11. painter->setFont( QFont("Arial",14,QFont::Cursive));
  12. painter->drawText(NameRect,Qt::AlignRight,entry.GetSurename());
  13. }
  14. }
To copy to clipboard, switch view to plain text mode 
Here I'm placing Name and Surename.

On the proxy side I have QSortFilterProxyModel.
Qt Code:
  1. bool MySortFilterProxyModel::lessThan(const QModelIndex &left,const QModelIndex &right) const
  2. {
  3. Person leftData = sourceModel()->data(left).value<Person>();
  4. Person rightData = sourceModel()->data(right).value<Person>();
  5.  
  6. QString leftString = leftData.GetName();
  7. QString rightString = rightData.GetName();
  8.  
  9. return QString::localeAwareCompare(leftString, rightString) < 0;
  10. }
  11.  
  12. bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
  13. const QModelIndex &sourceParent) const
  14. {
  15. QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
  16. Person data = sourceModel()->data(index0).value<Person>();
  17. QString strData = data.GetName();
  18. return (strData.contains(filterRegExp()));
  19. }
To copy to clipboard, switch view to plain text mode 
This stuff works so far.

Now I have 2 problems.
1. If I set the proxy filter e.g. on 'Da' the proxy is also filtering-out the Letter-Caption 'D', so that the List looks like
-----------------------
|Daniel Familly-Name |
-----------------------
What I have tried is to add a additional flag in my person class (Letter Caption yes/ no) and than to check this flag in filterAcceptsRow(). But than the list looks like this

-----------------------
|A |
-----------------------
-----------------------
|C |
-----------------------
-----------------------
|D |
-----------------------
|Daniel Familly-Name |
-----------------------
The letter-captions should only be drawn when there is a name.

My 2. problem is:
How can I convince Paint() and sizeHint() to draw this letter-captions in a
different way. (height of cell,BG-Color)?

Anyhow, I think that UserRoles could be the solution for my problems,
but my experiments with UserRoles were not really successful.

Have you any ideas how I could implement something like this, or is there
a better way of doing this, than the way I tried?

Thanks!