How to paint the Person data on list and table view with delegate paint method
General and Desktop
6
Posts
3
Posters
1.3k
Views
1
Watching
-
Hello guys!
I have a trouble, I have Person data, model and delegate classes, Now I want to put all the information( including image icon of person) into the view cell, I must do it with paint() in delegate,
so when I set the delegate to the view the cells should be filled with person data(including image it's important). How can I do it, can you give me some piece of code, here is what I started@ void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{if(index.isValid()) { Person person = index.model()->data(index,Qt::DisplayRole).value<Person>(); if(option.state & QStyle::State_Selected) { painter->fillRect(option.rect,option.palette.highlight()); } painter->drawPixmap(0,0,QPixmap(person.getIcon())); painter->drawText(option.rect,person.getName(),QTextOption()); }}
@it is very important for me and very thank you if you can help me
[edit: corrected typo in guys SGaist]
-
Hi,
What are you currently getting ? What are you expecting ?