ParameterTree hiding nested groups

42 views
Skip to first unread message

WodkaRHR

unread,
Nov 20, 2018, 4:57:14 PM11/20/18
to pyqtgraph

Hello together,

I currently am desining a ParameterTree with nested GroupParameters. So far so good. One group (I will call it group_a) has n+1 children:
  • index : A parameter that can take int values
  • n times another GroupParameter, where each of these GroupParameters represents a different "index".
What I want to do: Only show the one of the n subgroups, which index matches the value of the 'index' subparameter. That is, whenever I change the value of the 'index' parameter in group_a, I want to:
  1. hide all n GroupParameters in group_a
  2. show the one of the n GroupParameters that matches the value of the 'index' parameter of group_a
What I implemented so far works kind of:

import os
import pyqtgraph.parametertree.ParameterTree as ParameterTree
from pyqtgraph.parametertree import Parameter, parameterTypes
from pyqtgraph.Qt import QtCore, QtGui

class
MyGroup(parameterTypes.GroupParameter):

    def __init__(self, *args):
       super().__init__(name='GroupA')
       self.addChild(parameterTypes.ListParameter(name='idx', values=[0, 1, 2, 3], value=0))
       for i in range(4):
           self.addChild(Parameter.create(name=str(i), type='group', children=[{
               'name' : 'member', 'type' : 'str'
           }]))
       self.update_value()

    def treeStateChanged(self, param, changes):
       if param is self.child('idx'):
           # Show the element at this index
           self.update_value()
       
   def update_value(self):
       # Destroy the old child
       for child in self.children():
           if child.name() != 'idx':
               child.hide()
       idx = self.child('idx').value()
       self.child(str(idx)).show()


tree.addParameters(MyGroup())
win = QtGui.QWidget()
layout = QtGui.QGridLayout()
win.setLayout(layout)
layout.addWidget(tree)
win.show()

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
   import sys
   if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
       QtGui.QApplication.instance().exec_()


When I call this method in the constructor, everything works fine, only the group with the default value of the 'index' parameter of group_a is shown. However, once the Tree is visible and I change the value of the 'index' parameter in GroupA, the respective subgroups will neither be hidden nor shown. Is there any good solution to this issue? Or am I doing something wrong?

WodkaRHR

unread,
Nov 20, 2018, 6:29:54 PM11/20/18
to pyqtgraph
Also i tried to add
super().treeStateChanged(param, changes)

To the treeStateChanged method of the class, however with no results.
Reply all
Reply to author
Forward
0 new messages