Hi,
Am trying to subclass an item Delegate (to display images on QTableView cells),
I reimplemented QItemDelegate::paint() and QItemDelegate::sizeHint().
When I tested it, the function paint() is not called at all.
Here is my code
{
Q_OBJECT
public:
};
class ItemImageDelegate : public QItemDelegate
{
Q_OBJECT
public:
ItemImageDelegate(QObject*) ;
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
};
To copy to clipboard, switch view to plain text mode
{
qDebug()<<"Paint called";
}
{
qDebug()<<"Size Hint called";
}
ItemImageDelegate::ItemImageDelegate(QObject *parent = 0) : QItemDelegate(parent) {}
void ItemImageDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
qDebug()<<"Paint called";
}
QSize ItemImageDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
{
qDebug()<<"Size Hint called";
}
To copy to clipboard, switch view to plain text mode
// Main class
// setting the model ...
view->setModel(model);
ItemImageDelegate delegate(this);
view->setItemDelegate(&delegate);
view->resizeColumnsToContents();
view->show();
// Main class
// setting the model ...
QTableView* view = new QTableView();
view->setModel(model);
ItemImageDelegate delegate(this);
view->setItemDelegate(&delegate);
view->resizeColumnsToContents();
view->show();
To copy to clipboard, switch view to plain text mode
It seems so wierd to me, am for sure missing something, but I can't figure it out
Please help
Happy coding for all !!
Bookmarks