On Fri, Nov 30, 2018, 7:52 AM kiteh <[email protected]> wrote: > After tinkering some more with my code, using your example as a basis, I > sort of get it to work... My bad on this :) > > I do have a question though.. My company is using qt designer version > 4.8.5 which is pretty old, I guess? > Even so, when I was trying to get the list of widgets and its position > within using the following code: > for i in range(self.layout().count()): > item_name = self.layout().itemAt(i).objectName() > print "Name - {}, Position - {}".format(item_name, i) > > It seems to works for all other widgets with the exception of > QHorizontalLayout and QVerticalLayout in which in the designer version I am > using, it does not have a "objectName" field and hence it errors out for me > as there are 2 instances where I am using the above mentioned layout each. >
You would need to account for the fact that itemAt() returns a QLayoutItem, which wraps the actual layout object (in order to get its object name) http://doc.qt.io/archives/qt-4.8/qlayoutitem.html > Luckily, while these 2 layouts are the top 2 widgets, I can use > `self.layout().takeAt(0)` > or `self.layout().takeAt(1)` and re-insert them to be the last second and > third in position. > > Even so, is there a better way that I can query the index? > Since indexOf() only tells you the index of widgets in the layout, you would have to loop over each item the way you are doing and compare the item to a particular layout to get its index. This could be made into a method like self._layoutIndexOf(layout, item) If item is an instance of QWidget then you can call layout.indexOf(item) Otherwise you have to loop over all the items and if the loop item is a QLayoutItem then you have to do currentItem.layout() == item > > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/ae2d37a0-feeb-4e50-813d-716068552e01%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/ae2d37a0-feeb-4e50-813d-716068552e01%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1fJRbXLpr6uUaTPqyAsWXdatjkKM-FDvaAJKd_hxzszw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
