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. Highlight tree item
QtWS25 Last Chance

Highlight tree item

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.8k 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.
  • sajis997S Offline
    sajis997S Offline
    sajis997
    wrote on last edited by
    #1

    Hello forum,

    I have loaded a node database into the tree view. To increase the usability i also have a line edit so that the user finds it easier to scroll to a particular tree item once the item entered in the line edit matches any of the item inside the tree view.

    I would have the following functionalities:

    1. Matched tree item gets high-lighted.
    2. If the item resides inside the un-expanded parent item, it will be highlighted after it has been expanded.

    I got to look at the QSortFilterProxyModel and but the related examples shows how the the items filtered with the regular expression and the table views is also altered to reflect the filtered items. The altercation results is removing item from the views, which i do not want to have. I just want to get the tree item high-lighted.

    I hope to get some tips to implement this mechanism into my project.

    Thanks
    Sajjad

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      Hi sajis, Only that item has to highlight ? or that has to expand?

      1 Reply Last reply
      0
      • sajis997S Offline
        sajis997S Offline
        sajis997
        wrote on last edited by
        #3

        Hi

        If the item is hidden inside the parent item, which happens in case of the parent item is not expanded, then i would like the parent items to be expanded so that the requested tree item is visible and highlighted.

        Otherwise, it only needs to be highlighted as you understand.

        Lets take an example . Please go to the following link:

        http://www.student.itn.liu.se/~sajis997/nodetree.png

        You can see a tree view containing several tree items. Suppose that i have enterd something inside the QLineEdit which matches the item residing inside "X3DShaderNode". Since this item is already expanded , we only need to highlight the item that matches any of its children.
        If it were not expanded then we would have need it to be both expanded and then highlight the matched child item. If the matched child item in turns contains children , i do not need to expand the child item

        I hope i explained the issue . Let me know your idea to solve it.

        Regards
        Sajjad

        1 Reply Last reply
        0
        • sajis997S Offline
          sajis997S Offline
          sajis997
          wrote on last edited by
          #4

          I am still waiting for some suggestion over the issue i posted last time over the very same thread.

          Anyone ?

          If i have not clarified enough please let me know.

          Regards
          Sajjad

          1 Reply Last reply
          0
          • W Offline
            W Offline
            winkle99
            wrote on last edited by
            #5

            Your explanation is a little confusing, but I'll give it a shot.

            I'm assuming that what you're trying to do is, based on certain criteria, highlight an element in your QTreeView. What I've found helpful in applying special attributes to elements in a QTreeView (or any of the Qt Model Views) is to add a delegate that draws the cell in a special way. I usually use QModelIndex::data and QModelIndex::setData to set and test these criteria.

            So, for example, in my delegate (see QItemDelegate and its examples) I may do something like

            @if ( index.data( Qt::UserRole + 5).toBool() == true )
            painter->fillRect( option.rect, Qt::green); // that will draw the background cell in the special highlight color.@

            One nice thing about this approach is that the QItemDelegate will only draw if the node is visible. You get that part for free.

            1 Reply Last reply
            0

            • Login

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