Making a custom PyQt widget that imitates a frameLayout

44 views
Skip to first unread message

Erik Spellerberg

unread,
May 27, 2020, 9:01:25 AM5/27/20
to Python Programming for Autodesk Maya
I need a widget that looks and behaves like mayas native frameLayout with a title, arrow icon and you can click it to expand and collapse.

Currently I have borrowed a hacky sollution that converts the layout into a maya frameLayout, but it doesn't refresh when I dock the window so I have to change the window size when docked for all the widgets to display at the right location.
I would rather make a proper custom PyQt widget that has the elements that I want, but I really don't know how to go about it.

Justin Israel

unread,
May 27, 2020, 5:20:46 PM5/27/20
to python_in...@googlegroups.com
If you can't fine an existing example of an "accordion" layout/widget, and you wanted to create from from scratch,  I would suggest creating a widget that has a vertical layout. The first item would be your title bar, which contain a swizzle/triangle type icon. The second item in the layout would probably be a QScrollWidget if you want the layout to handle automatically scrolling. Or it could be a QStackedWidget if you want to to set any widget into it, which may already be a scroll widget. Then you can wire up your swizzle button to toggle the visibility of the main content widget. 
When these individual layout items are added to another vertical layout, with either a top alignment, or having a stretcher added as the last item, the toggling of the accordion items will cause them to compress up to the top.

Justin


--
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/dffb898a-a57e-4324-ba11-46d4905a2e18%40googlegroups.com.

Nicolas Combecave

unread,
May 28, 2020, 3:04:56 AM5/28/20
to python_in...@googlegroups.com
The method Justin describes closely matches the one we use.
To avoid dealing with icons, we use those character codes to draw the arrows:

Nicolas

Erik Spellerberg

unread,
May 28, 2020, 7:39:48 AM5/28/20
to Python Programming for Autodesk Maya
I understand it in theory but I've just never seen an example of a custom widget being written. Is it just a new class that inherits QtWidget and I populate it with the objects that I want? Then insert instances of that class into my layout?

Stefan Tapper

unread,
May 28, 2020, 8:14:07 AM5/28/20
to Python Programming for Autodesk Maya
I think this is a good example of a custom widget:

Regarding the accordion style widget.. (I'm not familar with maya widgets) isn't that exactly what a QToolBox does? It also inherits from QTabWidget which has a method "addCornerWidget" which shoiuld make it possible to implement the triangle button without hacks.

Justin Israel

unread,
May 28, 2020, 3:47:36 PM5/28/20
to python_in...@googlegroups.com


On Thu, May 28, 2020, 11:39 PM Erik Spellerberg <erik.spe...@gmail.com> wrote:
I understand it in theory but I've just never seen an example of a custom widget being written. Is it just a new class that inherits QtWidget and I populate it with the objects that I want? Then insert instances of that class into my layout?

Yes, that is right. 
You could do it without a custom class, but it just means you have to either assemble a list of widgets in a loop, or make a function that can assemble an item, and then a loop that adds each item to a layout. But then you are getting pretty close to just wrapping it up into custom widget classes. 
The end result may be 2 custom classes. One that is a collapsible item. And one that is the accordion widget containing the main layout to which multiple collapsible items are added or removed. This makes the whole thing reusable. 


On Wednesday, May 27, 2020 at 11:20:46 PM UTC+2, Justin Israel wrote:

If you can't fine an existing example of an "accordion" layout/widget, and you wanted to create from from scratch,  I would suggest creating a widget that has a vertical layout. The first item would be your title bar, which contain a swizzle/triangle type icon. The second item in the layout would probably be a QScrollWidget if you want the layout to handle automatically scrolling. Or it could be a QStackedWidget if you want to to set any widget into it, which may already be a scroll widget. Then you can wire up your swizzle button to toggle the visibility of the main content widget. 
When these individual layout items are added to another vertical layout, with either a top alignment, or having a stretcher added as the last item, the toggling of the accordion items will cause them to compress up to the top.

Justin

--
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.
Reply all
Reply to author
Forward
0 new messages