如果Webkit.WebView是Gtk.Grid的子代,为什么不显示它?

问题描述 投票:1回答:1

the first gjs tutorial中,它显示了如何创建仅包含Gtk.ApplicationWindowWebKit.WebView。该页面上给出的示例代码对我来说很好用。

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

此代码:

WebView

给出一个仅包含标签的窗口,其中 _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,则会看到两个元素。

strace显示程序is正在加载HTML。

我想念什么?

javascript gnome gnome-3 gjs
1个回答
0
投票

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

尝试:

Gtk.Label
© www.soinside.com 2019 - 2024. All rights reserved.