Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get TreeItem from within TreeView delegate?
Forum Updated to NodeBB v4.3 + New Features

How to get TreeItem from within TreeView delegate?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 311 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SRaD
    wrote on last edited by
    #1

    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?
    
        }
        // ...
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved