【问题标题】:PyQt4 QComboBox Signals and SlotsPyQt4 QComboBox 信号和槽
【发布时间】:2012-01-11 01:37:23
【问题描述】:

有没有一种方法可以创建一个信号,该信号在打开组合框并且用户使用键盘上的向上 - 向下箭头选择项目时断言。到目前为止,Qt4 参考列出了仅在单击鼠标或返回键后才激活的信号。我尝试了 highlight(int) 并且仅在再次单击鼠标时才有效,但是当我使用向上/向下箭头时,仅检索到单击的第一个项目。我认为当前突出显示的索引是通过 self.ui.cb_dspBenchCmds.currentText() 返回的索引。

这是一个代码 sn-p:

class CmdRef(Qg.QMainWindow):
    def __init__(self,parent = None):
    ........
    Qc.QObject.connect(self.ui.cb_dspBenchCmds, Qc.SIGNAL("activated(int)"), self.chooseCmd)
    ........

    def chooseCmd(self):
        whichCmd = self.ui.cb_dspBenchCmds.currentText()
        cmdDescription = self.dictDspCmds[str(whichCmd)]
        self.ui.te_dspBenchOutput.setText(''.join(cmdDescription))

谢谢

戴夫

【问题讨论】:

    标签: python pyqt signals-slots qcombobox


    【解决方案1】:

    highlighted 信号确实是您想要的信号。

    你只需要使用传递的值:

    class CmdRef(Qg.QMainWindow):
        def __init__(self, parent = None):
            ...
            self.ui.cb_dspBenchCmds.highlighted['QString'].connect(self.chooseCmd)
            ...
    
        def chooseCmd(self, whichCmd):
            cmdDescription = self.dictDspCmds[str(whichCmd)]
            self.ui.te_dspBenchOutput.setText(''.join(cmdDescription))
    

    【讨论】:

    • 感谢您的建议。那正是我想要的。出于某种原因,我不得不使用旧样式的 SIGNAL/SLOT 语法,因为使用“较新”样式的“突出显示”部分的属性错误。
    猜你喜欢
    • 1970-01-01
    • 2015-03-01
    • 1970-01-01
    • 2012-02-12
    • 2019-07-25
    相关资源
    最近更新 更多