Is too bad idea to create a widget with the QCreator an use it to render all I need? (To avoid doing it manually)
Here is an example
class CustomItemDelegate : public QStyledItemDelegate
{
WidgetItem * witem;
public:
CustomItemDelegate()
{
witem = new WidgetItem ();
}
~CustomItemDelegate()
{
delete witem;
}
{
witem->resize(option.rect.size());
/*
Here update the witem with some method with the real item data
Update labels, icons, and so on
*/
painter->save();
painter->translate(option.rect.topLeft());
witem->render(painter);
painter->restore();
}
}
class CustomItemDelegate : public QStyledItemDelegate
{
WidgetItem * witem;
public:
CustomItemDelegate()
{
witem = new WidgetItem ();
}
~CustomItemDelegate()
{
delete witem;
}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
witem->resize(option.rect.size());
/*
Here update the witem with some method with the real item data
Update labels, icons, and so on
*/
painter->save();
painter->translate(option.rect.topLeft());
witem->render(painter);
painter->restore();
}
}
To copy to clipboard, switch view to plain text mode
Note that the widget is create just once and then all its components updated
Bookmarks