3

In the first gjs tutorial, it shows how to create a Gtk.ApplicationWindow which contains only a WebKit.WebView. The example code given on that page works fine for me.

But if I modify that code to create a Gtk.Grid and put the WebView in that, it shows up blank instead of displaying the HTML.

This code:

 _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();
 }

gives a window containing only the label, with this._page taking up zero space. If instead I set this._page to a new Gtk.Label, I see both elements.

strace shows that the program is loading the HTML.

What am I missing?

Marnanel Thurman
  • 261
  • 1
  • 10

1 Answers1

2

The WebView's preferred and natural width and height are 0 pixels, and it is not set to expand horizontally or vertically, so it is not allocated any space.

Try:

        this._page.set_hexpand(true);
        this._page.set_vexpand(true);
wjt
  • 970
  • 7
  • 16