keyPress event: ignore or accept

97 views
Skip to first unread message

Luigi Ferraris

unread,
Oct 9, 2015, 12:29:59 PM10/9/15
to QtContribs
Hi Pritpal,
I need your help to remember about events: stop and/or propagation.

I have a form with one and only one widget: a QLineEdit. QLineEdit is connected to: QEvent_KeyPress event and "textEdited(QString)" signal.

I want (e.g.):
- reject the "0" (zero) WITHOUT stop the event handler. Is out of any logic?
- reject the "1" and stop the event handler.

Anyway, here a snipped code
METHOD __my_QKeyPress( oKeyEvent ) CLASS something

   LOCAL nKey := oKeyEvent:key()

   IF nKey == Qt_Key_0
      oKeyEvent:ignore()
      RETURN .F.
   ENDIF

   IF nKey == Qt_Key_1
      oKeyEvent:ignore()
      RETURN .T.
   ENDIF

   // any other key will be accepted, so
   oKeyEvent:accept()

RETURN .F.


Related with "1" works fine: QlineEdit doesn't get "1"
Related with "0" it doesn't works because QLineEdit get "0"

If I remember well, I can't use currentHbQtObject:keyPressEvent( oKeyEvent ) to call the base class: right?

TIA
Luigi Ferraris

Pritpal Bedi

unread,
Oct 22, 2015, 3:12:55 PM10/22/15
to QtContribs
Hi Luigi

I have a form with one and only one widget: a QLineEdit. QLineEdit is connected to: QEvent_KeyPress event and "textEdited(QString)" signal.


Sorry for delay.

Please refer to hbqtwidgets/getsys.prg and related sources.
How events are handled in QLineEdit are clearly demonstrated
in that code. It is really difficult to rely on our standard key handeling 
mechanism as far as QLineEdit is concerned as many keys are filtered 
by Qt itself.


Pritpal Bedi
a student of software analysis & concepts

 
Reply all
Reply to author
Forward
0 new messages