Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-59354

QTreeWidget::setchildIndicatorPolicy(DontShowIndicator) hides child nodes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.9.0 Alpha
    • Widgets: Itemviews
    • None

    Description

      Directed to post a bug after posting a question here:

      https://forum.qt.io/topic/76961/expand-all-qtreewidget-items-and-hide-all-expansion-indicators/3

      I don't want the user to be able to collapse the nodes, so I use setChildIndicatorPolicy:

      QTreeWidgetItem* last = tree->topLevelItem(tree->topLevelItemCount() - 1);
      while(last)
      {
      	last->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator);
      	last = last->child(last->childCount() - 1);
      }
      

      However, doing this hides all the children below the first level

      The documentation for QTreeWidgetItem::DontShowIndicator says

      The controls for expanding and collapsing will never be shown even if there are children. If the node is forced open the user will not be able to expand or collapse the item.

      Manually setting the item expanded doesn't work

      QTreeWidgetItem* last = tree->topLevelItem(tree->topLevelItemCount() - 1);
      while(last)
      {
      	last->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator);
      	last->setExpanded(true);
      
      	last = last->child(last->childCount() - 1);
      }
      

      Note that QTreeModel::hasChildren always returns {[false}} if the indicator policy is don't show.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            steve.lorimer Steve Lorimer
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes