【问题标题】:Why doesn't a Webkit.WebView display if it's a child of a Gtk.Grid?如果 Webkit.WebView 是 Gtk.Grid 的子项,为什么它不显示?
【发布时间】:2020-01-26 21:39:30
【问题描述】:

the first gjs tutorial 中,它显示了如何创建一个仅包含WebKit.WebViewGtk.ApplicationWindow。该页面上给出的示例代码对我来说很好。

但是,如果我修改该代码以创建 Gtk.Grid 并将 WebView 放入其中,它会显示为空白而不是显示 HTML。

这段代码:

 _buildUI() {

    this._window = new Gtk.ApplicationWindow  ({
            application: this.application,
            title: "example",
            window_position: Gtk.WindowPosition.CENTER });

    this._label = new Gtk.Label({label:"This is a label"});

    this._page = new Webkit.WebView ();
    this._page.load_uri (GLib.filename_to_uri (GLib.get_current_dir() +
            "/something.html", null));

    this._grid = new Gtk.Grid();
    this._grid.attach(this._label, 0, 0, 1, 1);
    this._grid.attach(this._page,  0, 1, 1, 1);

    this._window.add (this._grid);

    this._window.show_all();
 }

给出一个只包含标签的窗口,this._page 占用零空间。相反,如果我将 this._page 设置为新的 Gtk.Label,我会看到这两个元素。

strace 显示程序正在加载 HTML。

我错过了什么?

【问题讨论】:

    标签: javascript gnome gnome-3 gjs


    【解决方案1】:

    WebView 的首选和自然宽度和高度为 0 像素,并且未设置为水平或垂直扩展,因此不分配任何空间。

    试试:

            this._page.set_hexpand(true);
            this._page.set_vexpand(true);
    

    【讨论】:

    • 天才。非常感谢! (哎呀。很高兴见到你。)
    猜你喜欢
    • 2012-01-24
    • 2018-12-05
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    • 2018-04-25
    • 2021-08-24
    • 1970-01-01
    • 2012-10-21
    相关资源
    最近更新 更多