Delay action to wait for user interaction
Delay action to wait for more user input
UsecaseHave you ever created a text filter that can be used to filter a (big) item view so users can get to their content faster? If you did, you probably simply connected
QLineEdit::textChanged ( const QString & text )
There are many such cases where events can happen in quick succession, and you’d like your application to respond to these changes. On the one hand, it makes sense to respond to as many of those events in one go as possible, but on the other hand you don’t want the update to take too much time after the user is done typing his filter string (or whatever it is you are waiting for).
One solution to this problem is to use two timers, one short enough so an update will still appear snappy but long enough that it will probably not trigger before there is more input (for instance, if the user is not done typing his filter), and one longer timer that will trigger a set time after the first event happened, so the update will not be delayed forever as more and more events happen that would otherwise delay the update.The
That’s all. Of course, you can tweak the timings by either passing in a reasonable minimum and maximum delay in the constructor, or using the setters for these.
And here’s the CPP code: