我如何找出 GTK 需要哪些 GDK 事件? 信号?
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我想我现在明白你的意思了,我发现这个表匹配了 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.
假设我已经正确解释了您的问题,您希望将 Glade 文件中指定的信号连接到源代码中的函数。 如何执行此操作取决于您是否使用 libglade 来加载生成的文件或 GtkBuilder,两者都很相似,但为了完整起见,我将提供 C 语言示例。
使用 libglade 你会这样做:
使用 GtkBuilder 会像这样:
当使用 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:
Using GtkBuilder it would be like this:
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
您可以使用
gdk_event_handler_set( )
首先在启动时注册您自己的 GDK 事件处理程序:
...然后用它打印出任何有用的信息,并且不要忘记通过 gtk_main_do_event() 将事件传递给 GTK+ 就像这里:
You can capture the events with
gdk_event_handler_set()
First register your own GDK event handler on startup:
... 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: