I am trying to catch the highlighted signal from a QComboBox, but it is not being emitted consistently. So far I've found out that:
1. If QComboBox is not editable, the highlighted signal is emitted correctly.
2. If QComboBox is editable and uses the default convenience model (ie no call to setModel is made), the highlighted signal is emitted.
BUT:
3. If QComboBox is editable and it uses a model other than the default convenience model, the highlighted signal is not emitted.
I've tried this using both a standard QStringList model and a custom model.

Is there a reason for this behavior? Am I missing something?
A code example follows, where combos 1-3 illustrate the 3 cases outlined above, and combo3 is not emitting the highlighted signal while combos 1 and 2 are.

Thanks!

Qt Code:
  1. import sys
  2. from PyQt4 import QtCore
  3. from PyQt4 import QtGui
  4.  
  5. class TestWindow(QtGui.QWidget):
  6. def __init__(self, parent=None):
  7. super().__init__(parent)
  8. data_items = ['item1', 'item2', 'item3', 'item4']
  9. combo1 = QtGui.QComboBox(self)
  10. combo1.setEditable(False)
  11. combo1.setModel(QtGui.QStringListModel(data_items, self))
  12. combo1.highlighted.connect(lambda i: messages.append('combo1 emits highlighted signal, item={}'.format(i)))
  13. combo2 = QtGui.QComboBox(self)
  14. combo2.setEditable(True)
  15. combo2.addItems(data_items)
  16. combo2.highlighted.connect(lambda i: messages.append('combo2 emits highlighted signal, item={}'.format(i)))
  17. combo3 = QtGui.QComboBox(self)
  18. combo3.setEditable(True)
  19. combo3.setModel(QtGui.QStringListModel(data_items, self))
  20. combo3.highlighted.connect(lambda i: messages.append('combo3 emits highlighted signal, item={}'.format(i)))
  21. messages = QtGui.QTextEdit(self)
  22. layout = QtGui.QVBoxLayout()
  23. layout.addWidget(combo1)
  24. layout.addWidget(combo2)
  25. layout.addWidget(combo3)
  26. layout.addWidget(messages)
  27. self.setLayout(layout)
  28.  
  29.  
  30. if __name__ == "__main__":
  31. app = QtGui.QApplication(sys.argv)
  32. window = TestWindow()
  33. window.show()
  34. app.exec_()
To copy to clipboard, switch view to plain text mode