I have a simple list to show list of plugins in my program. To customize it i use delegate class derived from QStyledItemDelegate.
The code:
Qt Code:
  1. class PluginListDelegate : public QStyledItemDelegate
  2. {
  3. public:
  4. PluginListDelegate();
  5. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
  6. QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const;
  7. private:
  8. QFont line1;
  9. };
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. PluginListDelegate::PluginListDelegate() :
  2. line1("Tahoma",10,QFont::Bold,false)
  3. {
  4.  
  5. }
  6. void PluginListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
  7. {
  8. QStyledItemDelegate::paint(painter,option,index);
  9. ...
  10. ...
  11. }
  12.  
  13. QSize PluginListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
  14. {
  15. int width = 0,height = 0;
  16. QFontMetrics fm1(line1); // <-- crash here
  17. height = fm1.height() + 20;
  18. width = fm1.width(name) + 20;
  19. return QSize(width,height);
  20. }
To copy to clipboard, switch view to plain text mode 

Really don't understand what I do wrong.