Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
None
-
6.8.3
-
None
Description
In the code sample below there are two webview hosted in dockwidgets, one is docked by default and the other is floating.
Note that both webviews have the WA_NativeWindow flag set, so the the QMainWindow can stay on raster surface, not changing surface type.
Observations on WebView 1 initially docked:
- Docked it resizes and renders properly
- Undocked the webengine view is not rendering anymore
Observations on WebView 2 initially floating:
- Undocked/floating it resizes and renders properly
- When docking back, e.g. into the right docking area, it crashes on the D3D11 swapChain being null, see attached screenshot
Repo code sample:
#include <QtWidgets/QApplication> #include <QtWidgets/QtWidgets> #include <QWebEngineView> class CenterWidget : public QWidget { public: CenterWidget(QWidget* parent = nullptr) : QWidget(parent) {} void paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setPen(Qt::white); QRect _rect = rect(); painter.fillRect(_rect, QColor(100,100,100)); if (auto win = parentWidget()->windowHandle()) { QString surfaceStr("Unhandled"); switch (win->surfaceType()) { case QWindow::RasterSurface: surfaceStr = "Raster"; break; case QWindow::Direct3DSurface: surfaceStr = "Direct3D"; break; case QWindow::OpenGLSurface: surfaceStr = "OpenGL"; break; } painter.drawText(_rect, "Surface Type: " + surfaceStr, QTextOption(Qt::AlignCenter)); } } }; int main(int argc, char* argv[]) { QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); QApplication app(argc, argv); app.setQuitOnLastWindowClosed(true); // Create Top Level MainWindow auto mainWindow = new QMainWindow(); mainWindow->setAttribute(Qt::WA_DeleteOnClose); mainWindow->setWindowTitle(QString("WebView Bugs - Qt%1.%2.%3").arg(QT_VERSION_MAJOR).arg(QT_VERSION_MINOR).arg(QT_VERSION_PATCH)); mainWindow->setCentralWidget(new CenterWidget(mainWindow)); mainWindow->resize(800, 600); mainWindow->show(); // Create WebView 1 - Initially docked in the QMainWindow -> un-dock will not render WebView anymore auto webView1 = new QWebEngineView(); webView1->load(QUrl("https://qt-project.org/")); webView1->setAttribute(Qt::WA_NativeWindow); // For keeping raster surface on mainWindow auto dockWidget1 = new QDockWidget("WebView 1", mainWindow); dockWidget1->setAllowedAreas(Qt::AllDockWidgetAreas); mainWindow->addDockWidget(Qt::LeftDockWidgetArea, dockWidget1); dockWidget1->setWidget(webView1); // Create WebView 2 - Initially floating on top of the QMainWindow -> re-dock will crash on swapChain auto webView2 = new QWebEngineView(); webView2->load(QUrl("https://qt-project.org/")); webView2->setAttribute(Qt::WA_NativeWindow); // For keeping raster surface on mainWindow auto dockWidget2 = new QDockWidget("WebView 2", mainWindow); dockWidget2->setAllowedAreas(Qt::AllDockWidgetAreas); mainWindow->addDockWidget(Qt::RightDockWidgetArea, dockWidget2); dockWidget2->setWidget(webView2); dockWidget2->setFloating(true); // Run Qt message loop return app.exec(); }