class TimeLineDelegate : public QItemDelegate
{
Q_OBJECT
public:
TimeLineDelegate(QObject *o):QItemDelegate(o){}
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index);
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index);
};
我为自定义绘图QTreeWidget或QTreeView创建了此委托
但它不起作用,TimeLineDelegate::paint
未被调用
我尝试使用QTreeWidget和QTreeView,例如
QTreeView *myView = new QTreeView();
TimeLineDelegate *delegat = new TimeLineDelegate(myView);
myView->setItemDelegate(new TimeLineDelegate(this));
QStandardItemModel *myModel = new QStandardItemModel();
QStandardItem *parentItem = myModel->invisibleRootItem();
for (int i = 0; i < 4; ++i) {
QStandardItem *item = new QStandardItem(
QString("item %0").arg(i));
parentItem->appendRow(item);
if (i == 0)
parentItem = item;
else {
item->setData(34);
}}
myView->setModel(myModel);
myView->show();