How to modify style hint without QProxyStyle?

元气小坏坏 提交于 2019-12-02 06:48:58

The menu popup delay is not a fixed value, as it will depend on the current style. There is no way to set it programmatically.

The Qt way to modify style hints for existing styles is via QProxyStyle. However, even that is not guaranteed to work for user-defined or third-party styles, because they are not obliged to call QStyle.proxy(). And even if they did, neither PyQt nor PySide wrap any classes that are based on plugins (which includes QProxyStyle).

The only way to get full control over the behaviour of style-hints is to write your own, application-specific style class. But, of course, you would then no longer be modifying the style-hints of an existing style, so that is beyond the scope of the current question.

That seems to leave one remaining option, which is to subclass QMenu and bypass the style-hint altogether. Grepping the Qt source code reveals that (disregarding the various style classes) the only places where SH_Menu_SubMenuPopupDelay is used is within the mouseMoveEvent of QMenu. So it might be possible to reimplement that to get the behaviour you want.

UPDATE:

The QProxyStyle class is now available in PyQt5.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!