Is there a way to distinguish between programmatic index changes and user selection index changes?

qt

Solution

I remember there being a way to suspend triggering events in Qt, so you can do that, before and after changing `currentIndex`.

Ah, and here it is:

bool oldState = comboBox->blockSignals(true);
comboBox->setCurrentIndex(5);
comboBox->blockSignals(oldState);

Problem

I have a QComboBox. I have two use cases. In one use case, the combo box is programmatically changed to have a new index via setCurrentIndex(). In the other use case, the user clicks and selects a new combo box selection with the mouse. Both of these use cases trigger the QComboBox::currentIndexChanged(int) signal. This is a major problem for the code I am trying to port. In the old framework (not Qt), a similar callback mechanism would be called only if the user selected an item and not if the index programmatically changed. How can I mimic this behavior in Qt?

Original source