2011-02-27 51 views
1

我正在开发一个Qt应用程序,我想知道树视图的项目是否在委托函数中展开。如何检查树视图的项目是否在委托中展开?

这里是我的树视图的委托..

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? */ 
} 

我认为这是可能使用树视图的指针和isExpanded()函数,但我不知道我怎样才能获得委托函数指针。

谢谢。

回答

2

您可以使用option参数来检查给定的项目是否展开;下面是一个例子:

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

希望这会有所帮助,至于

+0

谢谢。我解决了我的问题。 – Brian 2011-02-28 00:54:35

相关问题