Maya and PyQt - Checkboxes are not displaying correctly for QMenus/QActions..

27 views
Skip to first unread message

kiteh

unread,
May 3, 2019, 1:28:41 PM5/3/19
to Python Programming for Autodesk Maya
Hi all,

I am trying to implement a right-arrow in my QMenus and as soon as I did that, it seems to have screw up my checkboxes?


The checkboxes you are seeing in the gif are actually QAction objects. Wondering if anyone has experience this before and/or if this is a Maya/Qt issue (I couldn't tell which is which) or if this could be one of the instance where Maya does not plays nicely with Qt?

I am using the following line of code to set the right-arrow in my QMenu subclass:
self.setStyleSheet("QMenu::right-arrow{image:url(add.png);}")


Marcus Ottosson

unread,
May 3, 2019, 2:19:12 PM5/3/19
to python_in...@googlegroups.com

Yes, I’ve seen this too. Using CSS, some widgets require that you re-define not just individual elements, but the entirety of the widget and all of its children. So what’s happened here is that all elements of the menu forgot about any default styling as soon as you apply a stylesheet to the parent QMenu. I don’t think there’s any way to style just one element, I’ve always resorted to re-styling the whole thing, so if you find any, let me know!


--
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/7e29642a-2dbb-4dd2-a2de-e2621c4e7b61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin Israel

unread,
May 3, 2019, 5:09:56 PM5/3/19
to python_in...@googlegroups.com


On Sat, May 4, 2019, 6:19 AM Marcus Ottosson <konstr...@gmail.com> wrote:

Yes, I’ve seen this too. Using CSS, some widgets require that you re-define not just individual elements, but the entirety of the widget and all of its children. So what’s happened here is that all elements of the menu forgot about any default styling as soon as you apply a stylesheet to the parent QMenu. I don’t think there’s any way to style just one element, I’ve always resorted to re-styling the whole thing, so if you find any, let me know!

It isn't the same issue as where you define one aspect of the style and the widget loses all the other defaults from the QStyle. It is caused by this being CSS (Cascading Style Sheets) and the "cascading" being the key word here. The current form of that CSS selector is applying to the object and all of its children. The menu has child menus so every matching checkable action that is a descendent is being affected. 
The qt stylesheet reference describes the different syntax for selectors :

There is a form of the selector that applies only to a specific object by its id:

    #myObjectName 

Or more specifically:

    QMenu#myObjectName 

This would allow you to set unique object names on the menus and control them individually. 
Otherwise the alternative is to not parent the menus to each other but rather the same top level widget. 


On Fri, 3 May 2019 at 18:28, kiteh <kiteh...@gmail.com> wrote:
Hi all,

I am trying to implement a right-arrow in my QMenus and as soon as I did that, it seems to have screw up my checkboxes?


The checkboxes you are seeing in the gif are actually QAction objects. Wondering if anyone has experience this before and/or if this is a Maya/Qt issue (I couldn't tell which is which) or if this could be one of the instance where Maya does not plays nicely with Qt?

I am using the following line of code to set the right-arrow in my QMenu subclass:
self.setStyleSheet("QMenu::right-arrow{image:url(add.png);}")


--
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/7e29642a-2dbb-4dd2-a2de-e2621c4e7b61%40googlegroups.com.
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 python_inside_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages