PyQt4 QComboBox信号和插槽

时间:2011-12-01 22:36:47

标签: python pyqt signals-slots qcombobox

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

这是一段代码:

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))

感谢

戴夫

1 个答案:

答案 0 :(得分:2)

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))