简体   繁体   English

PyQt4 QComboBox信号和插槽

[英]PyQt4 QComboBox Signals and Slots

is there a way to create a signal that asserts when a combo box is opened and user uses the up - down arrows on the keyboard to select an item. 有没有办法创建一个信号,当组合框打开时断言,用户使用键盘上的向上箭头选择一个项目。 So far the Qt4 reference lists signals that activate only after a mouse click or return key hit. 到目前为止,Qt4参考列出了仅在鼠标单击或返回键命中后激活的信号。 I tried highlighted(int) and that only worked with another mouse click but when i use the up/down arrows, only the first item that was clicked is retrieved. 我尝试使用突出显示(int)并且只能使用另一个鼠标点击,但是当我使用向上/向下箭头时,只检索被点击的第一个项目。 I thought the current highlighted index is the one that is returned via self.ui.cb_dspBenchCmds.currentText(). 我认为当前突出显示的索引是通过self.ui.cb_dspBenchCmds.currentText()返回的索引。

here's a code snippet: 这是一段代码片段:

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

thanks 谢谢

dave 戴夫

The highlighted signal does appear to be the one you want. highlighted信号似乎确实是您想要的信号。

You just need to make use of the passed value: 您只需要使用传递的值:

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

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

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