我如何找出 GTK 需要哪些 GDK 事件? 信号?

发布于 2024-07-18 13:42:26 字数 376 浏览 5 评论 0原文

我使用 Glade-3 进行 GUI 设计,但一直遇到这个问题。 我在 GTK+ 文档中或 Glade-3 (3.4.5) 中没有看到任何将信号映射到事件的内容。 GTK+源代码中是否有地方可以找到这些信息?

注意:在这个问题中,重要的是要认识到事件和信号在 GTK 中不是同一件事。

示例:

我有一个事件框,需要以下事件才能接收以下信号。 如何确定给定信号需要哪些事件?

Events: GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK
Signals: leave_notify_event, enter_notify_event

I'm using Glade-3 for my GUI design, but I keep hitting this problem. I don't see anything in the GTK+ documentation mapping signals to events or in Glade-3 (3.4.5). Is there a place in the GTK+ source code to find this information?

Note: It is important in this question to recognize that events and signals are NOT the same thing in GTK.

Example:

I have an eventbox that requires the following events in order to receive the following signals. How do I determine what events are required by a given signal?

Events: GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK
Signals: leave_notify_event, enter_notify_event

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

快乐很简单 2024-07-25 13:42:26

好吧,我想我现在明白你的意思了,我发现这个表匹配了 gtk 信号和 gdk 事件。 这里

Ok, I think I know what you mean now, I found this table matching up the gtk signals and gdk events. Here it is.

忆梦 2024-07-25 13:42:26

假设我已经正确解释了您的问题,您希望将 Glade 文件中指定的信号连接到源代码中的函数。 如何执行此操作取决于您是否使用 libglade 来加载生成的文件或 GtkBuilder,两者都很相似,但为了完整起见,我将提供 C 语言示例。

使用 libglade 你会这样做:

GladeXml *xml = glade_xml_new(filename, NULL, NULL); // Load the file
glade_xml_signal_autoconnect(xml); // Connect the signals

使用 GtkBuilder 会像这样:

GtkBuilder *xml = gtk_builder_new();
gtk_builder_add_from_file(xml, filename, NULL); // Load the file
gtk_builder_connect_signals(xml, NULL); // Connect the signals

当使用 GtkBuilder 时,信号连接函数中的第二个参数可以替换为指向数据的指针,然后该数据将被传递到信号处理程序。

展望未来,我建议使用 GtkBuilder,因为 libglade 即将被弃用。

链接

以下是有关上述两个函数的相关文档的链接

Assuming that I have interpreted your question correctly you are wanting to connect the signals you specified in the Glade file to the functions in the source code. How you do this depends if you are using libglade to load the files generate or GtkBuilder, both are similar but I will give samples in C just to be complete.

Using libglade you would do it like so:

GladeXml *xml = glade_xml_new(filename, NULL, NULL); // Load the file
glade_xml_signal_autoconnect(xml); // Connect the signals

Using GtkBuilder it would be like this:

GtkBuilder *xml = gtk_builder_new();
gtk_builder_add_from_file(xml, filename, NULL); // Load the file
gtk_builder_connect_signals(xml, NULL); // Connect the signals

When using GtkBuilder the second parameter in signal connect function can be replaced with a pointer to data which will then be passed to the signal handlers.

Going forward I would suggest using GtkBuilder as libglade is on its way to being deprecated.

Links

Here are the links to the relevent documentation about the two functions mentioned above

清醇 2024-07-25 13:42:26

您可以使用 gdk_event_handler_set( )

首先在启动时注册您自己的 GDK 事件处理程序:

gdk_event_handler_set(my_gdk_event_handler, NULL, NULL);

...然后用它打印出任何有用的信息,并且不要忘记通过 gtk_main_do_event() 将事件传递给 GTK+ 就像这里:

void my_gdk_event_handler(GdkEvent *event, gpointer data)
{
    printf("Received GdkEvent of type %d", event->type);

    gtk_main_do_event(event); // Pass event to GTK+
}

You can capture the events with gdk_event_handler_set()

First register your own GDK event handler on startup:

gdk_event_handler_set(my_gdk_event_handler, NULL, NULL);

... Then use it to print out any useful information, and don't forget to pass the event to GTK+ through gtk_main_do_event() like here:

void my_gdk_event_handler(GdkEvent *event, gpointer data)
{
    printf("Received GdkEvent of type %d", event->type);

    gtk_main_do_event(event); // Pass event to GTK+
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文