Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-137466

QWebEngineView not rendering when setting WA_NativeWindow after constructor call

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.8.3
    • Qt RHI
    • None
    • Windows

    Description

      When setting the WA_NativeWindow on a QWebEngineView it seems to be order dependent to get the webengineview actually to render its content.
      The code example below shows 3 different ways of setting the WA_NativeWindow flag and calling load(url), where the first example which is imo the expected order fails.

      Example WebView 1:

      • Sets WA_NativeWindow directly after the webview constructor
      • Calls load(url) after flag setting
        -> This order, which seems to me the natural way of setting things up, doesn't work and the webview is not rendering at all

      Example WebView 2:

      • Sets WA_NativeWindow directly after the webview constructor
      • Calls load(url) at the very end when the dialog is already shown
        -> This order works, webview is rendering

      Example WebView 3:

      • Calls load(url) directly after the webview constructor
      • Sets WA_NativeWindow after the load(url) call
        -> This order works, webview is rendering

       

      Repro code sample:

      #include <QtWidgets/QApplication>
      #include <QtWidgets/QtWidgets>
      #include <QWebEngineView>
      
      int main(int argc, char* argv[])
      {
      	QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
      	QApplication app(argc, argv);
      	app.setQuitOnLastWindowClosed(true);
      	
      	// Create WebView 1 -> Not rendering!
      	auto dlg1 = new QDialog();
      	dlg1->setWindowTitle("WebView 1");
      	auto horzLayout1 = new QHBoxLayout(dlg1);
      	auto webView1 = new QWebEngineView();
      	webView1->setAttribute(Qt::WA_NativeWindow);
      	webView1->load(QUrl("https://qt-project.org/")); // load after set WA_NativeWindow
      	horzLayout1->addWidget(webView1);
      	dlg1->resize(320, 200);
      	dlg1->show();
      
      	// Create WebView 2 -> Works
      	auto dlg2 = new QDialog();
      	dlg2->setWindowTitle("WebView 2");
      	auto horzLayout2 = new QHBoxLayout(dlg2);
      	auto webView2 = new QWebEngineView();
      	webView2->setAttribute(Qt::WA_NativeWindow);
      	horzLayout2->addWidget(webView2);
      	dlg2->resize(320, 200);
      	dlg2->move(dlg1->frameGeometry().bottomLeft());
      	dlg2->show();
      	webView2->load(QUrl("https://qt-project.org/")); // load after show() and WA_NativeWindow
      
      	// Create WebView 3 -> Works
      	auto dlg3 = new QDialog();
      	dlg3->setWindowTitle("WebView 3");
      	auto horzLayout3 = new QHBoxLayout(dlg3);
      	auto webView3 = new QWebEngineView();
      	webView3->load(QUrl("https://qt-project.org/")); // load before set WA_NativeWindow
      	webView3->setAttribute(Qt::WA_NativeWindow);
      	horzLayout3->addWidget(webView3);
      	dlg3->move(dlg2->frameGeometry().bottomLeft());
      	dlg3->resize(320, 200);
      	dlg3->show();
      	
      	// Run Qt message loop
      	return app.exec();
      }
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            lagocs Laszlo Agocs
            roman_w Roman Woelker
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes