Create a delegate to display custom data

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-07-01 19:31:56 -03:00 committed by Dirk Hohndel
parent 1b8f7f53f2
commit 3b0936eca3
2 changed files with 27 additions and 0 deletions

View file

@ -476,3 +476,21 @@ QSize HTMLDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModel
doc.setTextWidth(options.rect.width());
return QSize(doc.idealWidth(), doc.size().height());
}
LocationFilterDelegate::LocationFilterDelegate(QObject *parent)
{
}
void LocationFilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
painter->drawText(QPoint(0, 0), index.data().toString());
painter->restore();
}
QSize LocationFilterDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize size;
size.setWidth(option.rect.width());
size.setHeight(20);
}

View file

@ -129,4 +129,13 @@ public:
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
class LocationFilterDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
LocationFilterDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
};
#endif // MODELDELEGATES_H