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:
class PluginListDelegate : public QStyledItemDelegate
{
public:
PluginListDelegate();
private:
};
class PluginListDelegate : public QStyledItemDelegate
{
public:
PluginListDelegate();
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const;
private:
QFont line1;
};
To copy to clipboard, switch view to plain text mode
PluginListDelegate::PluginListDelegate() :
line1
("Tahoma",
10,
QFont::Bold,
false){
}
{
QStyledItemDelegate::paint(painter,option,index);
...
...
}
{
int width = 0,height = 0;
height = fm1.height() + 20;
width = fm1.width(name) + 20;
return QSize(width,height
);
}
PluginListDelegate::PluginListDelegate() :
line1("Tahoma",10,QFont::Bold,false)
{
}
void PluginListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyledItemDelegate::paint(painter,option,index);
...
...
}
QSize PluginListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
int width = 0,height = 0;
QFontMetrics fm1(line1); // <-- crash here
height = fm1.height() + 20;
width = fm1.width(name) + 20;
return QSize(width,height);
}
To copy to clipboard, switch view to plain text mode
Really don't understand what I do wrong.
Bookmarks