QTreeView和代表(

时间:2014-04-08 10:32:45

标签: qt delegates

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();

1 个答案:

答案 0 :(得分:0)

您忘记了const方法的paint说明符。见full signature