79708741

Date: 2025-07-21 08:06:37
Score: 0.5
Natty:
Report link

Thanks to the comments by @musicamante, I realized that I had misunderstood how QMenu works in relation to QActions (which is also reflected in the OP code).

So, if I want to style the item that displays "Options", even if it is created via options_menu = CustomMenu("Options", self), I actually have to set the style in the QMenu that ends up containing this item - which is the menu = QMenu(self).

So, a quick hack of the OP code to demonstrate this is:

# ...
    def contextMenuEvent(self, event):
        menu = QMenu(self)
        style = MenuProxyStyle()          # added
        style.setBaseStyle(menu.style())  # added
        menu.setStyle(style)              # added
# ...

With this, the application renders the "Options" menu as disabled, however reaction to mouse move events is still active, so the submenu popup opens as usual:

app screenshot

... which is basically what I was looking for in OP.

Except, now all items in the main context menu = QMenu(self) appear disabled, whereas I wanted to select only certain items in the menu to appear disabled - so now will have to figure that out ...

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @musicamante
  • Self-answer (0.5):
  • High reputation (-1):
Posted by: sdbbs