nodegui / nodegui-plugin-webview

[WIP] A NodeGui plugin that adds webview support
29 stars 5 forks source link

Can't add Webview as Widget to Another Layout #22

Open apedemak opened 2 years ago

apedemak commented 2 years ago

For whatever reason the Webview only seems to work in its own window. Once I try to add the Webview as a widget to the layout of another element, the app no longer launches.

WORKING EXAMPLE (EXAMPLE #1):

import { QWebEngineView, QWebChannel } from "nodegui-plugin-webview";
const webview = new QWebEngineView();
webview.setInlineStyle("align-self:'stretch';");
webview.load("http://google.com");

const channel = new QWebChannel();
webview.page().setWebChannel(channel);

webview.show();
(global as any).wv = webview;

NOT WORKING EXAMPLE (EXAMPLE #2):

import { QWebEngineView, QWebChannel } from "nodegui-plugin-webview";
import {
  QMainWindow,
  QWidget,
  FlexLayout,
  QPushButton
} from "@nodegui/nodegui";

const win = new QMainWindow();
const center = new QWidget();
const webview = new QWebEngineView();
webview.setInlineStyle("align-self:'stretch';");
webview.load("http://google.com");

const channel = new QWebChannel();
webview.page().setWebChannel(channel);

const button = new QPushButton();
button.setText("Hello");

center.setLayout(new FlexLayout());
center.layout?.addWidget(webview);
center.layout?.addWidget(button);
win.setCentralWidget(center);
win.show();
(global as any).win = win;

Example #1 works and the app launches, example #2 produces this error:

The app starts to launch, then closes immediately.

No sure what is going on.

apedemak commented 1 year ago

Following up on this Issue.

Why can't the Webview be used as a "Child View" like any other widget?

Even the example/demo (Demo.ts) breaks and shows an error if you try and use the Webview as a child/widget.

It works only if you allow the widget to open in a new window.