Discussion:
[pyqtgraph] ParameterTree hiding nested groups
WodkaRHR
2018-11-20 21:57:13 UTC
Permalink
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?
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/ac2970fd-7726-4db2-a35c-69c7bc11ffac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
WodkaRHR
2018-11-20 23:29:53 UTC
Permalink
Also i tried to add
super().treeStateChanged(param, changes)

To the treeStateChanged method of the class, however with no results.
--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/b78d1492-69e8-48a7-bfff-f61d5e29cce9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...