Re: key_press_event for drawing area.



On 7/4/05, Deekshit M <dmantamp yahoo com> wrote:
   Is it possible to attach key_press_event for
drawing_rea. That is the key pressed when the
drawing_area has the focus.

Yes, but it's more complicated than you think :-(

You need to arrange for your drawing area to be "focusable", and it
has to be able to indicate to the user that it has the keyboard focus.
You need to subclass drawingarea and implement
size_request/size_allocate (allow space for the focus indicator),
expose_event (draw the focus indicator plus any drawing you do), event
(grab the focus on left-click), set the GTK_CAN_FOCUS flag in init,
and gtk_widget_add_events(GDK_KEY_PRESS_MASK).

I'd have a look at the gtk sources, or perhaps someone has a simple
example somewhere? This is the bit of my app that does this:

http://cvs.sourceforge.net/viewcvs.py/vips/nip2-7.11/src/imagepresent.c?rev=1.1.1.1&view=markup

But there's other stuff in there too, so it's not so easy to read.

John



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]