开发者

How to check whether the tree view's item is expanded in delegate?

开发者 https://www.devze.com 2023-02-13 13:02 出处:网络
I\'m developing a Qt application and I want to know whether the tree view\'s item is expanded in delegate function.

I'm developing a Qt application and I want to know whether the tree view's item is expanded in delegate function.

Here is my tree view's delegate..

void roster_item_delegate::paint(QPainter *painter,
                                 const QStyleOptionViewItem &option,
                                 const QModelIndex &index) const
{
    /* How can I know whether this item is expanded or not in here? */
}

I think 开发者_开发知识库it's possible using the tree view's pointer and isExpanded() function, but I don't know how can I obtain the pointer in delegate function.

Thank you.


you can use the option parameter to check of the given item is expanded; below is an example:

void MyItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const
{
    QStyle::State state = option.state;
    if ((state & QStyle::State_Open) > 0)
        qDebug() << index.data(0) << " item is expanded";

    QStyledItemDelegate::paint(painter, option, index);
}

hope this helps, regards

0

精彩评论

暂无评论...
验证码 换一张
取 消