Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. WebView in QuickWidget on macOS - broken??
Forum Updated to NodeBB v4.3 + New Features

WebView in QuickWidget on macOS - broken??

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 322 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danryu
    wrote on last edited by danryu
    #1

    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"
        }
    }
    

    quickwidget.pro

    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.

    Screenshot 2022-06-26 162242.png

    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.

    Screen Shot 2022-06-26 at 16.14.38.png

    Can anybody help me get this working correctly?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved