连接到 Vala 中的scroll_event
我一直在努力连接到 TextView 小部件的滚动事件。我可以将 lambda 连接到它,然后运行我的方法,但我想了解为什么直接连接不起作用。我一直在使用下面的代码
using Gtk;
public class TextFileViewer : Gtk.Window {
private TextView text_view;
public TextFileViewer () {
this.title = "Text File Viewer";
this.position = WindowPosition.CENTER;
set_default_size (400, 300);
this.text_view = new TextView ();
this.text_view.editable = true;
this.text_view.cursor_visible = true;
var scroll = new ScrolledWindow (null, null);
scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
scroll.add (this.text_view);
this.text_view.scroll_event.connect (on_scroll_event);
var vbox = new VBox (true, 0);
vbox.pack_start (this.text_view, true, true, 0);
add (vbox);
}
private void on_scroll_event () {
stderr.printf("We scrollin breds");
}
public static int main (string[] args) {
Gtk.init (ref args);
var window = new TextFileViewer ();
window.destroy.connect (Gtk.main_quit);
window.show_all ();
Gtk.main ();
return 0;
}
}
该代码给了我错误:
gtkviewer.vala:20.46-20.60: error: Argument 1: Cannot convert from `TextFileViewer.on_scroll_event' to `Gtk.Widget.scroll_event'
scroll.scroll_event.connect (on_scroll_event);
vala is at version 0.12.0
I've been struggling to connect to the scroll_event of a TextView widget. I can connect a lambda to it, and then run my method, but I'd like to understand why directly connecting doesn't work. I've been using the code below
using Gtk;
public class TextFileViewer : Gtk.Window {
private TextView text_view;
public TextFileViewer () {
this.title = "Text File Viewer";
this.position = WindowPosition.CENTER;
set_default_size (400, 300);
this.text_view = new TextView ();
this.text_view.editable = true;
this.text_view.cursor_visible = true;
var scroll = new ScrolledWindow (null, null);
scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
scroll.add (this.text_view);
this.text_view.scroll_event.connect (on_scroll_event);
var vbox = new VBox (true, 0);
vbox.pack_start (this.text_view, true, true, 0);
add (vbox);
}
private void on_scroll_event () {
stderr.printf("We scrollin breds");
}
public static int main (string[] args) {
Gtk.init (ref args);
var window = new TextFileViewer ();
window.destroy.connect (Gtk.main_quit);
window.show_all ();
Gtk.main ();
return 0;
}
}
That code gives me the error:
gtkviewer.vala:20.46-20.60: error: Argument 1: Cannot convert from `TextFileViewer.on_scroll_event' to `Gtk.Widget.scroll_event'
scroll.scroll_event.connect (on_scroll_event);
vala is at version 0.12.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查 scroll-event 信号参数:
公共虚拟信号 bool scroll_event (Gdk.EventScroll event);
Check the scroll-event signal arguments:
public virtual signal bool scroll_event (Gdk.EventScroll event);