QTreeWidget multiple selected items

3,153 views
Skip to first unread message

Arjun Thekkummadathil

unread,
Jul 16, 2014, 12:08:22 AM7/16/14
to python_in...@googlegroups.com
Hi
   Am writing a tool which has a QTreeWidget and i need to get the selected items from the widget am only able to get one selection.

How do i get multiple selected items

-Arjun

Justin Israel

unread,
Jul 16, 2014, 1:23:20 AM7/16/14
to python_in...@googlegroups.com
What are you using now to get the selected items that isn't giving you the full selection? Is it QTreeWidget.selectedItems()?

What is your QTreeWidget set to for its SelectionBehavior and SelectionMode? Does it already allow multi-row selection but is not returning multiple rows?


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAJrOGy_vrEZgYkWvdaPeH2unpMSGnBu%3DrV0Z-NBFK26gdM8N8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Arjun Thekkummadathil

unread,
Jul 16, 2014, 1:50:17 AM7/16/14
to python_in...@googlegroups.com
I figured it out i was using QTreeWidget.selectedItems() but then i was expecting it to return multiple objects, it returns one object which is ideally a list


Justin Israel

unread,
Jul 16, 2014, 2:12:45 AM7/16/14
to python_in...@googlegroups.com
I'm not sure I follow. It should always be a list, with one or more items in it. So it technically always returns multiple items (0+)


Arjun Thekkummadathil

unread,
Jul 16, 2014, 2:30:02 AM7/16/14
to python_in...@googlegroups.com
yeah that's what even i thought but then it returns me a object and i can loop through that, that object is not of a type list its some kind of Qt object but luckily i can loop through that
for i in object:
    print i.text(columnNumber)

that gives me the values


Justin Israel

unread,
Jul 16, 2014, 5:39:33 AM7/16/14
to python_in...@googlegroups.com
Are you using an old version of PyQt maybe? Because I am testing PyQt 4.8.6 in Maya 2013, using the default sip API v1, and QTreeWidget.selectedItems() returns a plain list of QTreeWidgetItems:

from PyQt4 import QtCore, QtGui

tree = QtGui.QTreeWidget()
tree.setSelectionMode(t.ExtendedSelection)

for i in xrange(5):
    item = QtGui.QTreeWidgetItem(["test"])
    tree.addTopLevelItem(item)

tree.show()

# Selected 4 things in the tree
result = tree.selectedItems()
print type(result), len(result)
# <type 'list'> 4

It returns exactly what the docs say: A list of QTreeWidgetItems




Arjun Thekkummadathil

unread,
Jul 16, 2014, 5:52:44 AM7/16/14
to python_in...@googlegroups.com

Justin Israel

unread,
Jul 16, 2014, 6:03:29 AM7/16/14
to python_in...@googlegroups.com
PySide also returns a list in the versions I am testing. In your version is it actually returning a QList? I wasn't aware that those were actually exposed to python bindings. Everything I have tried returns a python list. I will have to check my version of PySide in Maya 2014 when I get back to work. 


Reply all
Reply to author
Forward
0 new messages