Dave
Dave

Reputation: 41

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. 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. I thought the current highlighted index is the one that is returned via 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

Upvotes: 3

Views: 1492

Answers (1)

ekhumoro
ekhumoro

Reputation: 120588

The highlighted signal does appear to be the one you want.

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

Upvotes: 2

Related Questions