我通过继承DrawingArea小部件来创建自定义小部件,它在cairo中绘制一个圆圈。我需要获得圈子点击的坐标。我将以下代码连接到实现信号,我配置为接收按钮
static void my_custom_widget_realize_cb (GtkWidget *widget)
{
MyCustomWidget *mycustomwidget = MY_CUSTOM_WIDGET (widget);
MyCustomWidgetPrivate *priv = mycustomwidget->priv;
GtkAllocation allocation;
GdkWindowAttr attr;
gint attr_mask;
GdkWindow *parent_window;
gtk_widget_get_allocation (widget, &allocation);
gtk_widget_set_realized (widget, TRUE);
attr.window_type = GDK_WINDOW_CHILD;
attr.x = allocation.x;
attr.y = allocation.y;
attr.width = allocation.width;
attr.height = allocation.height;
attr.wclass = GDK_INPUT_ONLY;
attr.event_mask = (gtk_widget_get_events (widget) |
GDK_KEY_PRESS_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK);
attr_mask = GDK_WA_X | GDK_WA_Y;
parent_window = gtk_widget_get_parent_window (widget);
gtk_widget_set_window (widget, parent_window);
g_object_ref (parent_window);
priv->window = gdk_window_new (parent_window, &attr, attr_mask);
gdk_window_set_user_data (priv->window, mycustomwidget);
}
接收button_press的重写回调未被调用。