Qt World Summit: Submit your Presentation

How to get TreeItem from within TreeView delegate?

  • My TreeView delegate captures when a user hovers over a specific item in the TreeView. I'm using a custom model derived from QAbstractItemModel which holds a plain class called MyTreeItem. Within each MyTreeItem is a member varaible that holds a unique id.

    Is there a way to obtain the item that the mousehover was detected over so that I can grab this id?

    void MyTreeViewDelegate::paint(QPainter *painter,
    const QStyleOptionViewItem &option, const QModelIndex &index) const
        // ...
        if (option.state & QStyle::State_MouseOver) {
            // how to get the item that has the mouseover here?
        // ...

  • Lifetime Qt Champion

    Isn't index enough? From there you can get all the data with QModelIndex::data()

Log in to reply