hi, im having a big problem with my custom delegate, heres the code from the mainwindow class:

Qt Code:
  1. mediaItemDelegate *delegate;
  2. ui->listView_2->setModel(model);
  3. ui->listView_2->setItemDelegate(delegate);
To copy to clipboard, switch view to plain text mode 

and the delegate itself

Qt Code:
  1. class mediaItemDelegate : public QItemDelegate
  2. {
  3. Q_OBJECT
  4. public:
  5. mediaItemDelegate(QObject *parent = 0);
  6.  
  7. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const = 0;
  8. QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const = 0;
  9.  
  10. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "mediaitemdelegate.h"
  2.  
  3. mediaItemDelegate::mediaItemDelegate(QObject *parent):
  4. QItemDelegate(parent)
  5. {
  6. }
  7.  
  8. void mediaItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
  9. {
  10. if(index.isValid()){
  11. const int left = option.rect.left();
  12. const int top = option.rect.top();
  13. const int width = option.rect.width();
  14. QFont titlefont(option.font);
  15. titlefont.setBold(true);
  16. titlefont.setPointSize(titlefont.pointSize());
  17. int height = (2 * titlefont.pixelSize()) + 10;
  18. int padding = 3;
  19. QColor foregroundColor = (option.state.testFlag(QStyle::State_Selected))?
  20. option.palette.color(QPalette::HighlightedText):option.palette.color(QPalette::Text);
  21. //base pixmap
  22. QPixmap pixmap(width, height);
  23. pixmap.fill(Qt::transparent);
  24. QPainter p(&pixmap);
  25. p.translate(-option.rect.topLeft());
  26.  
  27. //icon time
  28. QIcon icon;
  29. int iconwidth = height - 6;
  30. icon.addFile(QString::fromUtf8(":/icons/icons/hi48-action-filename-filetype-amarok.png"), QSize(iconwidth,iconwidth),QIcon::Normal, QIcon::On);
  31. if(!icon.isNull()){
  32. icon.paint(&p, left + padding, top + padding, iconwidth, iconwidth, Qt::AlignCenter, QIcon::Normal);
  33. }
  34.  
  35. //now for text
  36. QString artist, album, title,duration;
  37. QMap<int, QVariant> map(index.model()->itemData(index));
  38. title.append(map.value(mediaItem::TitleRole).toString());
  39. artist.append(map.value(mediaItem::ArtistRole).toString());
  40. album.append(map.value(mediaItem::AlbumRole).toString());
  41. duration.append(map.value(mediaItem::DurationRole).toString());
  42.  
  43. QFont font(option.font);
  44. font.setBold(true);
  45. int lefttext = iconwidth + 2 * padding;
  46. int topoff = (height - iconwidth) / 2;
  47. QTextOption txtopt(Qt::AlignLeft | Qt::AlignBottom);
  48. txtopt.setWrapMode(QTextOption::WordWrap);
  49. QRect titlerect(left + lefttext, top + padding, (width / 2) - padding - lefttext, topoff);
  50. QRect artistrect(left + lefttext, top + (2*padding) + topoff + 1, (width / 2) - padding - lefttext, topoff);
  51. QRect albumrect(left + lefttext + titlerect.width() + padding, top + (2*padding) + topoff + 1, (width / 2) - padding - lefttext, topoff);
  52. QRect durrect(left + lefttext + titlerect.width() + padding, top + padding, (width / 2) - padding - lefttext, topoff);
  53. font.setPixelSize(titlerect.height()/7);
  54. p.setFont(font);
  55. p.setPen(foregroundColor);
  56. p.drawText(QRectF(titlerect), title, txtopt);
  57. p.drawText(QRectF(artistrect), artist, txtopt);
  58. txtopt.setAlignment(Qt::AlignRight | Qt::AlignBottom);
  59. p.drawText(QRectF(albumrect), album, txtopt);
  60. p.drawText(QRectF(durrect), duration, txtopt);
  61. p.end();
  62.  
  63. //hey presto
  64. painter->drawPixmap(option.rect.topLeft(), pixmap);
  65. /*
  66.   QPixmap reflect = Utilities::reflection(pixmap);
  67.   painter->drawPixmap(option.rect.topleft() + QPoint(0, size.width() + 1), reflect);
  68.   */
  69. }
  70. }
  71.  
  72. QSize mediaItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
  73. {
  74. if(!index.isValid()){
  75. return QSize(0, 0);
  76. }
  77.  
  78. int width = 0;
  79. QFont titlefont(option.font);
  80. titlefont.setBold(true);
  81. titlefont.setPointSize(titlefont.pointSize());
  82. int height = (2 * titlefont.pixelSize()) + 10;
  83. return QSize(width, height);
  84. }
To copy to clipboard, switch view to plain text mode 

if anybody can shed some light on why this is segfaulting when i try to the the delegate with QListView::setItemDelegate I would be grateful as im nearly out of bourbon lol

ta janorcutt