Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How can I control visibilty of a row in a QML TreeView?

How can I control visibilty of a row in a QML TreeView?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 699 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.
  • T Offline
    T Offline
    Tuffa
    wrote on 13 Jun 2017, 15:39 last edited by
    #1

    I would like to control the visibility of a row in a QML TreeView based on model data, say based on data in a particular role.

    The only way of doing this appears to be: bind a condition to the RowDelegate's visible property, however it appears to be impossible to access model data from within a TreeView's rowDelegate.

    I have exhausted Google. Or vice versa!

    The nearest I think I have come is to use the TreeView's currentIndex property (see excerpt below), however when I examine the QModelIndex value received by the model's data() method, it reliably contains the following: QModelIndex(-1,-1,0x0,QObject(0x0)), which is not what I expect to see. Either this is a bug, or a TreeView's rowDelegate should not expect currentIndex to be set...

    Any help gratefully received!

    Chris.

    TreeView {
       style:  TreeViewStyle {
          ...
          rowDelegate: Rectangle {
             property bool isVisible : treeView.isCurrentItemCached()
             visible: isVisible
          }
       }
       id: treeView
       ...
       function isCurrentItemCached() {
          if (contentManager.content.data(currentIndex, "name") != undefined) {
             return contentManager.content.data(currentIndex, "name") != “Random String”
          } else {
             return false
          }
       }
    }
    
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tuffa
      wrote on 14 Jun 2017, 08:08 last edited by Tuffa
      #2

      Ah, I think I need to use QSortFilterProxyModel.

      1 Reply Last reply
      0

      1/2

      13 Jun 2017, 15:39

      • Login

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