[PySide2] - QTreeWidget > QStackedWidget

382 views
Skip to first unread message

Padraig Ó Cuínn

unread,
Apr 24, 2017, 2:23:16 PM4/24/17
to Python Programming for Autodesk Maya
Hi There everyone,

To get you upto scratch on my issue I will illustrate what I have and what I need. have a QWidget
Class with a QListWidget in the left with the name of two QTreeWidgets
linked inside it.
When I select "Tree_1" I can see tree one on the QStackedwidget and the same with tree_2. This works nicely if that is what you are after but

what I am looking for is the opposite action, I want to be able to select a QTreeWidgetItem on the left and display another layout or widget on the right.

The entire QTree will be driven from class objects so they all exist as usable objects. I am also looking to switch it from the QWidget into a QMainWindow as
the statusbar and menu will be useful to me.

thanks

Padraig

Justin Israel

unread,
Apr 24, 2017, 3:14:53 PM4/24/17
to Python Programming for Autodesk Maya


On Tue, Apr 25, 2017, 6:23 AM Padraig Ó Cuínn <patchquin...@gmail.com> wrote:
Hi There everyone,

To get you upto scratch on my issue I will illustrate what I have and what I need. have a QWidget
Class with a QListWidget in the left with the name of two QTreeWidgets
linked inside it.
When I select "Tree_1" I can see tree one on the QStackedwidget and the same with tree_2. This works nicely if that is what you are after but

what I am looking for is the opposite action, I want to be able to select a QTreeWidgetItem on the left and display another layout or widget on the right.

Where are you stuck? You said you are able to drive a layout from the selection in a list widget. What is not working when you try to drive the layout with a tree widget selection? 


The entire QTree will be driven from class objects so they all exist as usable objects. I am also looking to switch it from the QWidget into a QMainWindow as
the statusbar and menu will be useful to me.

thanks

Padraig

--
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/47b4ac96-1edd-4751-a7ea-4e691380813f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Apr 24, 2017, 4:39:10 PM4/24/17
to python_in...@googlegroups.com
A small runnable example would be super useful.​

Padraig Ó Cuínn

unread,
Apr 24, 2017, 6:36:57 PM4/24/17
to Python Programming for Autodesk Maya
Sorry for the silence,

this is what I have going at the moment

https://pastebin.com/AVJZ1yeA

Its is a listwidget with a stack holding two trees

I am looking for something with the opposite effect to that and not sure if it is do-able.
Basically I want to be able to select a branch on the tree and have it show an index of the stack per selection change.

Padraig.

Justin Israel

unread,
Apr 24, 2017, 7:06:36 PM4/24/17
to python_in...@googlegroups.com
Thanks for the example. Although I still am not clear where you are stuck. To answer your question, yes it is doable. But I am not exactly sure what you have tried that is not working as you expect? Have you tried creating a QTreeWidget on the left side and driving the stack via the selection? Did it fail? Have you tried using QTreeWidget.currentItemChanged signal to drive this?
 

Padraig.

--
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.

Padraig Ó Cuínn

unread,
Apr 24, 2017, 7:12:57 PM4/24/17
to Python Programming for Autodesk Maya
HI Justin Yup that is exactly what I tried just switching them around and seeing if the currentItemChange gave an event. It spat out an attribute error saying there is none with QTreeWidgetItem


Justin Israel

unread,
Apr 24, 2017, 7:18:27 PM4/24/17
to python_in...@googlegroups.com
On Tue, Apr 25, 2017 at 11:12 AM Padraig Ó Cuínn <patchquin...@gmail.com> wrote:
HI Justin Yup that is exactly what I tried just switching them around and seeing if the currentItemChange gave an event. It spat out an attribute error saying there is none with QTreeWidgetItem

Show, don't tell? If you can show us an approach that is not working, in addition to the traceback you are getting, I am positive we can identify a bug in your code. From a technical standpoint it should be completely possible to connect to the signals which are emitted when selection changes on the tree widget. But I feel you may have made an error in your approach.

 


--
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.

Padraig Ó Cuínn

unread,
Apr 24, 2017, 7:48:01 PM4/24/17
to Python Programming for Autodesk Maya
not a problem ill send you the tried code in the morning.

Padraig Ó Cuínn

unread,
Apr 27, 2017, 4:31:12 AM4/27/17
to Python Programming for Autodesk Maya
Here it is what I have so far sorry for the delay.
My main goal is to hook the Trees up for inheritance by classes.
If you move one from the other it loses inheritance and gains from the attached one.
I don't want the topItem to be able to be dropped or dragged on certain items (i.e build) but on the others I want it so the topItem becomes rootNode in the configuration.

right now I want to hook up the stack (I just threw in the list widget and table widget for visual).

https://pastebin.com/UQHrUcxt

Thank you for your time and patience lads.

Justin Israel

unread,
Apr 27, 2017, 7:09:24 AM4/27/17
to Python Programming for Autodesk Maya


On Thu, Apr 27, 2017, 8:31 PM Padraig Ó Cuínn <patchquin...@gmail.com> wrote:
Here it is what I have so far sorry for the delay.

Thank you for providing the start of the example code. 

My main goal is to hook the Trees up for inheritance by classes.
If you move one from the other it loses inheritance and gains from the attached one.

I don't follow what this means. Move one from which to where? Are you talking about dropping items within the same tree on the left? Or dropping them into the list or table on the right? I don't follow the reference to inheritance here. I think you might be making rigging references which I am not following. Someone else with relevant experience may understand this goal better than me. 

I don't want the topItem to be able to be dropped or dragged on certain items (i.e build) but on the others I want it so the topItem becomes rootNode in the configuration.

I get the desire to make some items draggable or able to receive drops. Which configuration? Is the drop supposed to happen within the tree? I see you have set drag drop to internal move. So I am not getting the relevance of the right side stack. 


right now I want to hook up the stack (I just threw in the list widget and table widget for visual).

Hook up the stack to do what? What should happen here? I see your initial tree items and list items and apparently a table which is not useful other than  for visuals? 

Sorry for seeming so dense. I just am not making the connections about the behaviours you want. Items are supposed to get dragged around into some configuration in either the tree or the list. And the stack index is supposed to be changed by some criteria of the selection or the drops. That is all I think I understand so far. 


Is there any more to this example that you haven't included, such as your non-working attempt to implement the behavior you have described? So far this is just a set of layouts, which I think I already understood from the previous mails. It would be much easier if I saw what you were trying to do with this currently passive layout. 



Thank you for your time and patience lads.

On Tuesday, 25 April 2017 00:48:01 UTC+1, Padraig Ó Cuínn wrote:
not a problem ill send you the tried code in the morning.

--
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.

Padraig Ó Cuínn

unread,
Apr 27, 2017, 2:08:06 PM4/27/17
to Python Programming for Autodesk Maya
HI Justin,

I total get why you are up in the air with this haha, It is because I am just prototyping with ideas in my head with what I want it to do.
My experience in QT is not basic but then again it is not as strong as I want it to be either.I will try to explain my main goal more explicitly.

1. The idea is to get a tree that has 3 or 4 topLevelItems and only 1 of them can be dropdraggable (the prebuild) this is because the top level item will be linked to the rootNode in maya. and maybe any part can be classed as a root node or joint.
2. I have a built up library of classes that create joints and limbs and everything in-between that will hook up to the branches and topLevelItems.
3. On the right I have a stack with a list and a table which is entirely just for visuals to show when I am able to actually get the stack switching from one page to another. The tree should only work within itself.
4. I want to toy with the idea of using the lineEdit as both a filter and a node installer. I have various other nodes that I would like the line edit only to recognize in the line edit, (** Only when the button is clicked ** ).. Other than this it should just work as a normal filter.
5.The tree will be relevant to the stack on the right not only by page but by nodes in mayas, so if i selected limb on the right a stack will show the limb window with leg/ arm/ finger/ toes etc and to choose how many segments per part.
6. I do have some code to hardcode from before show below

class UI(QMainWindow):
   
def __init__(self, *args, **kwargs):
       
QMainWindow.__init__(self, *args, **kwargs)
        main_wid
= QWidget(self)
       
self.setCentralWidget(main_wid)

        layout
= QHBoxLayout(self)
        main_wid
.setLayout(layout)

       
self.tree = QTreeWidget(self)
        layout
.addWidget(self.tree)

        item1
= QTreeWidgetItem('Bip')
       
self.tree.addTopLevelItem(item1)
        item2
= QTreeWidgetItem('Quad')
       
self.tree.addTopLevelItem(item2)

       
self.stack = QStackedWidget(self)
        layout
.addWidget(self.stack)

        page1
= QLabel('Please Change setting for your preferences', self)
       
self.stack.addWidget(page1)

        page2
= QLabel('Page2 : quad', self)
       
self.stack.addWidget(page2)
       
self.tree.itemSelectionChanged.connect(self.update_page)
       
self.show()

   
def update_page(self):
        item
= self.tree.currentItem()

       
# -- Do nothing if we don't have a current item
       
if not item:
           
return

       
# -- Check the item's text
       
if item.text(0) == 'Bip':
           
self.stack.setCurrentIndex(0)

       
else:
           
self.stack.setCurrentIndex(1)

       
# -- Or use the 'row'

        top_item_count
= self.tree.topLevelItemCount()
       
for i in xrange(top_item_count):
           
if item is self.tree.topLevelItem(i):
               
self.stack.setCurrentIndex(i)
               
return
This code works fine if it is needed for a hard coded project. But as I need it to be a bit more dynamic and switch from pages that are not even configured. This is where the lineEdit and button comes in.
Don't take notice of the indents as it is just the code that I am concerned about, trying to figure what does what.

Reply all
Reply to author
Forward
0 new messages