I'm programmatically changing the selected item with setCurrentIndex()
of my Tree- and TableViews.
If the current item has changed, a multitude of signals are emitted (currentChanged()
, currentColumnChanged
, etc).
I'm listening to some of these signals in order to be informed when the user changes the selection.
Is there a way/a signal to distinguish between user-selected and programmatically selected events?
I tried using the activated()
-signal on the views, but this seems to not behave the same way on different platforms (sometimes activated is triggered only if double-clicked).
CodePudding user response:
In your slot, you can use QObject::sender() to return the QObject to you. From there, there are a handful of ways you should be able to distinguish the source.
CodePudding user response:
Maybe, you could just block all signals while making your change?
QSignalBlocker or QObject::blockSignals could help:
{
const QSignalBlocker blocker(myWidget);
myWidget->setCurrentIndex(someIndex);
}