简体   繁体   English

PyQt5 QSpinBox 在上下文菜单中锁定/解锁

[英]PyQt5 QSpinBox Locking/Unlocking in Context Menu

I've added a locking checkbox in a spinbox's context menu that disables the spinbox using self.setDisabled(True) .我在微调框的上下文菜单中添加了一个锁定复选框,使用self.setDisabled(True)禁用微调框。 Is there any way I can open the context menu while the spinbox is disabled, to access the locking checkbox?有什么方法可以在旋转框被禁用时打开上下文菜单来访问锁定复选框?

Disabling a widget also makes it unresponsive to mouse and keyboard events, which obviously also prevents showing the context menu.禁用小部件还会使其对鼠标和键盘事件无响应,这显然也会阻止显示上下文菜单。

Instead of disabling it, use the readOnly property:不要禁用它,而是使用readOnly属性:

def setSpinEnabled(self, enabled):
    self.mySpecialSpin.setReadOnly(not enabled)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM