1. 需要加GDK_EXPOSURE_MASK和GDK_BUTTON_PRESS_MASK
2. 把GtkDrawingArea设为可接受焦点
gtk_widget_set_can_focus(videowidget, TRUE);
下面是为videowidget设置grab-focus事件并做相关动作
g_signal_connect(G_OBJECT(videowidget), "grab-focus" ,
G_CALLBACK(videoarea_grab_focus_cb) , NULL);
3.在button-press-event事件中grab focus
static gint
cb_videoarea_button_event_handler (GtkWidget *widget, GdkEventButton *event, gpointer data)
{
gtk_widget_grab_focus (widget);
}
4.在videowidget的expose-event中画焦点边框
static gboolean
videoarea_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
{
if (gtk_widget_has_focus(widget) == TRUE)
{
GtkStyle *style;
gtk_paint_focus(widget->style, widget->window,
GTK_STATE_SELECTED,
NULL, NULL, NULL, 0, 0,
widget->allocation.width-1,
widget->allocation.height-1);
}
阅读(2126) | 评论(0) | 转发(0) |