[Qt-interest] Event Filter

Andre Somers andre at familiesomers.nl
Wed Aug 11 20:50:15 CEST 2010


Op 11-8-2010 18:01, phil prentice schreef:
> Hi
>
>    I've been using QT for many years now, but I still consider myself a bit of
> a novice.  I am wondering if its better(more efficient) to use an
> event-filter or to sub-class widgets and catch events that way.
>
>    Basically I have an integer spin-box which increments in blocks of 5.  Only
> 5,10,15,....are valid inputs.  I dont want the user to be able to type in 6
> or 7 etc.  I dont know what the standard method is to do this, but my
> thinking is that the user should only be allowed to use the up&down arrows
> and keys to drive it.  So I thought that I might just stop keyboard numeric
> input.  I could sub-class or use an event filter.  Which would be best?
>
>    Secondly I have some other sub-classed frame objects that I need to detect
> if the mouse has been selected inside of them.  I could use the
> mousePressEvent() for those objects
> or
> I could again use the same event-filter (especially if I already have one
> available from above), but this time catching mouse events.  If I did'nt have
> the event-filter from above I would probably stick with the
> mousePressEvent().
>
> What would you all recommend?
>
>    
Perhaps look into using a QValidator?
Note that a user typing a 1 may just be on his way to typing 15 or 150, 
so while 1 is not valid in itself, it may lead to something valid.

André




More information about the Qt-interest-old mailing list