如何在 GtkOptionMenu/GtkComboBox 中禁用鼠标滚轮滚动

发布于 2024-09-30 22:24:41 字数 324 浏览 1 评论 0原文

有谁知道如何在 GtkOptionMenu 或 GtkComboBox 中禁用鼠标滚动?当您滚动窗口并且指针经过这样一个抓住焦点并更改值的小部件时,这很烦人!

我看到违规代码已添加回来了,但似乎没有任何机制来禁用此功能。

我正在使用 C 语言工作,但如果能提供任何语言的帮助,我们将不胜感激。

PS 我也许应该提到我正在使用 GTK 2.10,但需要与 GTK 2.4 兼容。

Does anyone know how to disable mouse scrolling in a GtkOptionMenu or GtkComboBox? It is annoying when you are scrolling through a window and the pointer passed over such a widget which grabs the focus and changes value!

I see that the offending code was added a while back, but there doesn't seem to be any mechanism in place to disable this functionality.

I am working in C, but help in any language would be much appreciated.

P.S. I should maybe mention that I'm using GTK 2.10, but need compatibility with GTK 2.4.

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

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

发布评论

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

评论(2

从此见与不见 2024-10-07 22:24:41

这有效 - 我希望可以帮助其他想做同样事情的人:

/* Create new closure (callback) to replace class default */   
GClosure * new_closure = 
  g_cclosure_new_object( G_CALLBACK(handler), /* my event handler */
                         G_OBJECT(gobject) /* use any static GObject to keep closure alive */
                       );

GType type = gtk_option_menu_get_type();

/* Get signal_id for "scroll_event" */
guint signal_id = g_signal_lookup("scroll_event", type);

/* Override default closure for scroll_event signal */
g_signal_override_class_closure(signal_id, type, new_closure);

This works - I hope might help someone else that wants to do the same thing:

/* Create new closure (callback) to replace class default */   
GClosure * new_closure = 
  g_cclosure_new_object( G_CALLBACK(handler), /* my event handler */
                         G_OBJECT(gobject) /* use any static GObject to keep closure alive */
                       );

GType type = gtk_option_menu_get_type();

/* Get signal_id for "scroll_event" */
guint signal_id = g_signal_lookup("scroll_event", type);

/* Override default closure for scroll_event signal */
g_signal_override_class_closure(signal_id, type, new_closure);
一枫情书 2024-10-07 22:24:41

您可以尝试禁用小部件上的滚动事件:

gtk_widget_set_events(GTK_WIDGET(box), gtk_widget_get_events(GTK_WIDGET(box)) & (GDK_ALL_EVENTS_MASK - GDK_SCROLL_MASK));

You could try disabling scroll events on the widget:

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