python Qt + hotkey,代码不起作用

设置了四个hotkey,另外三个都没问题,但是ctlr+o打开不起作用

相关代码:

    hk_new = Signal()
    hk_save = Signal()
    hk_open = Signal()
    hk_save_another = Signal()
    
    def __init__(self, parent=None):
        
        self.hk_new.connect(self.on_New_triggered)
        self.hk_save.connect(self.on_save_triggered)
        self.hk_open.connect(self.on_open_triggered)
        self.hk_save_another.connect(self.on_save_another_triggered)
        
        self.HK_new = SystemHotkey()
        self.HK_save = SystemHotkey()
        self.HK_open = SystemHotkey()
        self.HK_save_another = SystemHotkey()
        
        self.HK_new.register(("control", "n"), callback = lambda _:self.hk_new.emit())
        self.HK_save.register(("control", "s"), callback = lambda _:self.hk_save.emit())
        self.HK_open.register(("control", 'o'), callback = lambda _:self.hk_open.emit())
        self.HK_save_another.register(("control", "shift", "s"), callback = lambda _:self.hk_save_another.emit())

已经解决

该回答引用ChatGPT

可能是由于您在注册 HK_open 热键时使用了错误的参数。您可以尝试将 (control, o) 修改为 (control, "o"),这样它就能够正确地识别组合键 ctrl + o 了。修改后的代码示例如下:

self.HK_open.register(("control", "o"), callback = lambda _:self.hk_open.emit())