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
精彩评论