连接到 Vala 中的scroll_event

发布于 2024-11-05 16:21:48 字数 1432 浏览 4 评论 0原文

我一直在努力连接到 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 技术交流群。

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

发布评论

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

评论(1

望喜 2024-11-12 16:21:48

检查 scroll-event 信号参数:

公共虚拟信号 bool scroll_event (Gdk.EventScroll event);

private bool on_scroll_event (Gdk.EventScroll e) {
        stderr.printf("We scrollin breds");
        return true;
}

Check the scroll-event signal arguments:

public virtual signal bool scroll_event (Gdk.EventScroll event);

private bool on_scroll_event (Gdk.EventScroll e) {
        stderr.printf("We scrollin breds");
        return true;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文