3

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

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Dave
  • 41
  • 4

1 Answers1

2

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))
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • Thanks for the suggestion. That did exactly what i wanted. For some reason I had to use the old style SIGNAL/SLOT syntax because of an attribute error for the "highlighted" portion using the "newer" style. – Dave Dec 05 '11 at 03:26