WebView in QuickWidget on macOS - broken??
-
I have a Qt6 widgets-based app with a tabbed interface, that needs to load a webpage in one tab.
To do this I create a QuickWidget and load a simple QML WebView.
(Working with Qt 6.3.0 on macOS 11 and Windows 11.)However: the WebView does not display correctly on macOS, whereas it seems fine on Windows.
On macOS the webview appears as a blank white frame - but can be forced to appear buggily by adding a QMenu (see below).I am not trying to do anything exotic or experimental, as far as I know.
In fact I have really just taken the quickwidget example project, and added a QML WebView.
This should work, right? So why doesn't it?The working code below replicates the issue.
Download complete test project zip here: quickwidgetWeb.zip
main.cpp:
#include <QQuickWidget> #include <QtWebView> #include <QtWidgets> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(); }; MainWindow::MainWindow() { // need this on macOS to enable webview!?! QMenu *fileMenu = menuBar()->addMenu("someMenu"); QTabWidget *tabWidget = new QTabWidget; setCentralWidget(tabWidget); const QSize size(400, 400); QTextBrowser *textBrows = new QTextBrowser(); textBrows->setPlainText("Some plain text"); tabWidget->addTab(textBrows, "Plain text"); QQuickWidget *w = new QQuickWidget; w->resize(size); w->setResizeMode(QQuickWidget::SizeRootObjectToView); w->setSource(QUrl("qrc:quickwidget/webview.qml")); tabWidget->addTab(w, tr("WebView")); tabWidget->show(); } int main(int argc, char **argv) { QtWebView::initialize(); // at least necessary on Windows - webengine QApplication app(argc, argv); // this example and QQuickWidget are only functional when rendering with OpenGL QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL); MainWindow mainWindow; mainWindow.show(); return app.exec(); } #include "main.moc"
webview.qml
import QtQuick 2.0 import QtWebView 1.1 Item { WebView { id: webView anchors.fill: parent url: "https://qt.io" } }
QT += core gui quick widgets quickwidgets webview TARGET = quickwidget TEMPLATE = app CONFIG += qmltypes QML_IMPORT_NAME = QuickWidgetExample QML_IMPORT_MAJOR_VERSION = 1 SOURCES += main.cpp RESOURCES += quickwidget.qrc
This works fine on at least Windows. The non-webview tab is visible, and the web content displays when the webview tab is selected.
But on macOS the WebView is a blank white screen.
(NB: I had to set QT_WEBVIEW_PLUGIN=native in the Run environment to get past the "No WebView plug-in found!" error...)
Forcing (buggy) webview operation on macOS
If I set a QMenu in the MainWindow as shown in the main.cpp code example, then the WebView does display on macOS - BUT it seems that the OpenGL context sharing is broken? The WebView forces itself to the top layer, and can only be resized by maximizing and un-maximizing the window.Can anybody help me get this working correctly?