Selecting multiple items (using shift key) in Parameter Tree in pyqtgraph does not reflect properly in the UI

2,631 views
Skip to first unread message

Pranav

unread,
May 9, 2014, 4:34:06 AM5/9/14
to pyqt...@googlegroups.com

I have a parameter tree in my application.
For that tree when we set following properties:

 

tree = ParameterTree()      
tree
.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)


 

This actually enables multiple selection of nodes\items on the Parameter Tree. But in the UI when we perform below mentioned steps I can see an issue:
1. Select a node\item in tree.
2. Press and hold shift key.
3. Select another node\item in tree.
4. Release the shift key.

Notice that only first item on which we clicked and the next item we clicked appear to be selected.
Now as soon as I move my mouse over the items between the first and the last item that was clicked.. the  UI updates itself to show the items between them as selected.
Or If the parameter tree just loses focus then also all the items start to appear as selected.
Any idea why this is happening or how this can be resolved.
I know that Parameter Tree inherits from QTreeWidget which in turn inherits from QTreeView. I have explored its other selection modes but nothing works for the UI.

Luke Campagnola

unread,
May 10, 2014, 3:27:37 PM5/10/14
to pyqt...@googlegroups.com
On Fri, May 9, 2014 at 4:34 AM, Pranav <little.i...@gmail.com> wrote:

I have a parameter tree in my application.
For that tree when we set following properties:

 

tree = ParameterTree()      
tree
.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)


 

This actually enables multiple selection of nodes\items on the Parameter Tree. But in the UI when we perform below mentioned steps I can see an issue:
1. Select a node\item in tree.
2. Press and hold shift key.
3. Select another node\item in tree.
4. Release the shift key.

Notice that only first item on which we clicked and the next item we clicked appear to be selected.
Now as soon as I move my mouse over the items between the first and the last item that was clicked.. the  UI updates itself to show the items between them as selected.
Or If the parameter tree just loses focus then also all the items start to appear as selected.
Any idea why this is happening or how this can be resolved.

I am not able to reproduce this. Can you tell me the output of pg.systemInfo() on your machine?
 

I know that Parameter Tree inherits from QTreeWidget which in turn inherits from QTreeView. I have explored its other selection modes but nothing works for the UI.

ParameterTree actually inherits first from TreeWidget; perhaps you could test whether you have the same problem when running examples/TreeWidget.py ?

Luke

Pranav

unread,
May 12, 2014, 2:49:08 AM5/12/14
to pyqt...@googlegroups.com
Many thanks for your reply. Well I was not able to replicate the issue with either TreeWidget example or the Parameter Tree example.
 
But when I modified the sample to replicate my version of code I could see the issue. Here is a sample code with Parameter Tree:
 
import pyqtgraph as pg                                             
                                            
from pyqtgraph.Qt import QtCore, QtGui                                            
                                            
from pyqtgraph.parametertree import Parameter, ParameterTree                                            
                                            
                                            
                                            
                                            
app
= pg.mkQApp()                                            
                                            
                                            
                                            
                                            
#Defining parameters without value .. so that we don't get any undo arrow.                                            
                                            
test
= 'test'                                            
                                            
params = [                                            
                                            
{'name': 'Basic parameter data types', 'type': 'group', 'children': [                                            
                                            
{'name': test, },                                            
                                            
{'name': 'Float', },                                            
                                            
{'name': 'String', },                                            
                                            
{'name': 'List', },                                            
                                            
]},                                            
                                            
]                                            
                                            
                                            
                                            
                                            
p
= Parameter.create(name='params', type='group', children=params)                                            
                                            
                                            
                                            
                                            
t
= ParameterTree()                                            
                                            
t
.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)                                            
                                            
t
.setParameters(p, showTop=False)                                            
                                            
#t.setWindowTitle('pyqtgraph example: Parameter Tree')                                            
                                            
#t2 = ParameterTree()                                            
                                            
#t2.setParameters(p, showTop=False)                                            
                                            
                                            
                                            
                                            
win
= QtGui.QWidget()                                            
                                            
layout
= QtGui.QGridLayout()                                            
                                            
win
.setLayout(layout)                                            
                                            
layout
.addWidget(QtGui.QLabel("These are two views of the same data. They should always display the same values."), 0, 0, 1, 2)                                            
                                            
layout
.addWidget(t, 1, 0, 1, 1)                                            
                                            
#layout.addWidget(t2, 1, 1, 1, 1)                                            
                                            
win
.show()                                            
                                            
win
.resize(800,800)                                            
                                            
                                            
app
.exec_()


So only thing missing is when we dont give any value to the parameter item... this issue with multiseleciton is replicated. Let me know in case more information is required.

 

Also here is my system info:

 

sys.platform: win32
sys.version: 2.7.3 | 64-bit | (default, Aug  8 2013, 05:30:12) [MSC v.1500 64 bit (AMD64)]
qt bindings: PySide 1.1.1
pyqtgraph: 0.9.8; None
config:
{'antialias': False,
 'background': (0, 0, 0),
 'editorCommand': None,
 'enableExperimental': False,
 'exitCleanup': True,
 'foreground': (150, 150, 150),
 'leftButtonPan': True,
 'useOpenGL': False,
 'useWeave': True,
 'weaveDebug': False}

Pranav

unread,
May 12, 2014, 7:10:08 AM5/12/14
to pyqt...@googlegroups.com
Well thanks once again for pointing me to the examples.. I was able to compare and resolve my issue to an extent.
 
With the updated code the multi selection of nodes using shift key and mouse click is resolved.
 
import pyqtgraph as pg                                                                                                           
                                                                                                          
from pyqtgraph.Qt import QtCore, QtGui                                                                                                          
                                                                                                          
from pyqtgraph.parametertree import Parameter, ParameterTree                                                                                                          
                                                                                                          
                                                                                                          
                                                                                                          
                                                                                                          
app
= pg.mkQApp()                                                                                                          
                                                                                                          
                                                                                                          
                                                                                                          
                                                                                                          
#Defining parameters without value .. so that we don't get any undo arrow.                                                                                                          
                                                                                                          
test
= 'test'                                                                                                          
                                                                                                          
params = [                                                                                                          
                                                                                                          
{'name': 'Basic parameter data types', 'type': 'group', 'children': [                                                                                                          
                                                                                                          
{'name': test, 'type': 'str', 'value': ''},                                                                                                          
                                                                                                          
{'name': 'Float', 'type': 'str', 'value': ''},                                                                                                          
                                                                                                          
{'name': 'String', 'type': 'str', 'value': ''},                                                                                                          
                                                                                                          
{'name': 'List', 'type': 'str', 'value': ''},                                                                                                          
                                                                                                          
{'name': 'List2', 'type': 'str', 'value': ''},                                                                                                          
                                                                                                          
{'name': 'List3', 'type': 'str', 'value': ''},                                                                                                          
                                                                                                          
{'name': 'List4', 'type': 'str', 'value': ''},                                                                                                          
                                                                                                          
{'name': 'List5', 'type': 'str', 'value': ''},                                                                                                          
                                                                                                          
]},                                                                                                          
                                                                                                          
]                                                                                                          
                                                                                                          
                                                                                                          
p
= Parameter.create(name='params', type='group', children=params)                                                                                                          
                                                                                                          
                                                                                                          
t
= ParameterTree()
                                                                                                         
                                                                                                          
t
.setColumnCount(1)                                                                                                          
                                                                                                          
t
.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)                                                                                                          
                                                                                                          
t
.setParameters(p, showTop=False)                                                                                                          
                                                                                                          
win
= QtGui.QWidget()                                                                                                          
                                                                                                          
layout
= QtGui.QGridLayout()                                                                                                          
                                                                                                          
win
.setLayout(layout)                                                                                                          
                                                                                                          
layout
.addWidget(QtGui.QLabel("These are two views of the same data. They should always display the same values."), 0, 0, 1, 2)                                                                                                          
                                                                                                          
layout
.addWidget(t, 1, 0, 1, 1)                                                                                                          
                                                                                                          
win
.show()                                                                                                          
                                                                                                          
win
.resize(800,800)                                                                                                          
                                                                                                          
                                                                                                          
app
.exec_()

So I was able to resolve it by:

1. Adding value ans type column for the parameters being added to the tree.

2. t.setColumnCount(1): Setting the column count as 1 so that only one column is visible.

 

Though the above mentioned issue is resolve.. there is still one more issue with this version of code.

Try to do a Ctrl+A using keyboard .. notice that all the nodes are not selected. and as soon as the tree looses focus the nodes appear as selected. Simiar issue I was not able to replicate using Tree Widget.

Any suggestions !!

Pranav

unread,
May 15, 2014, 8:14:16 AM5/15/14
to pyqt...@googlegroups.com
So now issue is whenever we want to have some multiple selection then I need to  give 'type': 'str', 'value': ''  for a parameter selected. But my question is without this too the parameter tree should work. Let me know in case further input is required.

Pranav

unread,
Jun 4, 2014, 6:07:33 AM6/4/14
to pyqt...@googlegroups.com
Eventually I was able to resolve my issue:
 
The tree is added to a widget so I bring focus on the parent and then pull back the focus on the tree. This is dont in In tree's itemSelectionChanged event  Thus the item appear to be selected.
 

self.tree.parent().setFocus()

self.tree.setFocus()

Reply all
Reply to author
Forward
0 new messages