-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reimplement Qt3DWindow to work with Qt Webengine #53255
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jbp35 - thanks for the pull request! I have been looking into these issues in the last couple of days, and I am have been heading towards a similar solution but I am still testing various options. I have left a couple of comments.
Also a bunch of general questions:
- what operating system(s) have you been testing on?
- what Qt versions have you tried? Qt5 only, or also Qt6?
- what do you test to verify the PR has fixed the issues? (e.g. open a qgis 3d window, then open a webengine window, and they both work with no crash?)
Are you doing this to get PyQt5.QtWebEngineWidgets
working? Because for me, with similar implementation, import of this PyQt5 module would still fail with an import error:
QtWebEngineWidgets must be imported before a QCoreApplication instance is created
And it seems that getting this python module working may be a bit more tricky, because in QGIS, python gets initialized much later than when QApplication gets instantiated.
|
Ah ok, cool! The overall approach seems fine to me, so yeah, let's try to address the ugly details :-)
I see... I am on ubuntu 22.04, and I can see now that my For the time being I will stick to the existing PyQt5.QtWebEngineWidgets from my system, and use C++ code to test QtWebEngine inside QGIS... I am mainly concerned about having QGIS 3D running smoothly, even if QtWebEngine is used (for Qt6 we will probably need to move to QtWebEngine and finally ditch QtWebKit) |
Tests failed for Qt 6One or more tests failed using the build from commit db47e93 pointcloud_3d_singlecolor (testPointCloudSingleColor)pointcloud_3d_singlecolorTest failed at testPointCloudSingleColor at tests/src/3d/testqgspointcloud3drendering.cpp:272
pointcloud_3d_colorramp (testPointCloudAttributeByRamp)pointcloud_3d_colorrampTest failed at testPointCloudAttributeByRamp at tests/src/3d/testqgspointcloud3drendering.cpp:312
pointcloud_3d_classification (testPointCloudClassification)pointcloud_3d_classificationTest failed at testPointCloudClassification at tests/src/3d/testqgspointcloud3drendering.cpp:349
The full test report (included comparison of rendered vs expected images) can be found here. Further documentation on the QGIS test infrastructure can be found in the Developer's Guide. |
Finally managed to test this with both Qt5 and Qt6 on linux - and I can confirm things seems to be working fine even if there is a qt3d window and webengine window displayed at the same time, and without any scary warnings/errors from Qt. Well done @jbp35 and sorry for the long delay from me! I have added some minor sip and test fixes on the branch, and if all tests pass I think we should be good to merge this. |
@wonder-sk Thank you for the review! One doubt on my side, should we also bump dependencies for PyQtWebEngine (>= 5.15.6) and python3-pyqt5-sip (>=12.9) to avoid that users get an error when trying to run a plugin using QtWebEngineWidgets? |
I will try to add a summary of things here:
Sorry if some bits are not 100% correct - there are various things here I do not fully understand (OpenGL contexts + their sharing in Qt apps, WebEngine / Qt3D specifics of how OpenGL contexts are used). |
@jbp35 I have not really looked into that, I was primarily concerned about getting things work on C++ side of things. If there are some bumps of dependencies needed, that's something to sort out with QGIS packagers. Do you have some reference to what got fixed in those package versions? |
PyQt5-WebEngine >= 5.15.6 This is needed for QtWebEngineWidgets to work using python. PyQt6-WebEngine >= 6.2-maint Changelog for PyQt6:
This is needed for QtWebEngineWidgets to work using python. python3-pyqt5-sip >=12.9 I am not so sure that this is needed - it may just be that I was importing from PyQt5 instead of qgis.PyQt in my script above but I am not able to test this right now. |
I'm still not sure if I understand why |
When using WebEngine with python, PyQt5-WebEngine is intialized after the creation of QgsApplication. In old versions, PyQt5-WebEngine checks if a QApplication already exists during initialization and throw an error even if `AA_ShareOpenGLContexts' is enabled. In versions >= 5.16.6, it does not throw an error if `AA_ShareOpenGLContexts' is enabled and continue initialisation. |
This is a good summary. Regarding https://bugreports.qt.io/browse/QTBUG-60614, I think the logic is that Qt3DWindow is just a helper class to get started quickly with qt 3d (part of QT 3d Extras) and that it is meant to be reimplemented to suit project needs.. it is therefore unlikely that they will ever fix this and writing a custom class is the way to go. |
Ah ok, that makes sense - thanks for the clarification! To get the python packages upgraded, you will probably need to get in touch with package maintainers for various platform and ask them to do the upgrade - unfortunately there is no "official" registry of what package versions should be used with qgis installers... |
Alright, for reference I already opened a ticket for osgeo4W a few months ago: |
This is a follow-up of: #47873
Qt3DWindow is currently not compatible with Qt Webengine. As mentioned in QT doc, when using Qt::AA_ShareOpenGLContexts (which is required for Qt Webengine) it is strongly recommended to set the default QSurface format before the construction of the Qapplication. Otherwise, the format will not be applied to the global share context and therefore issues may arise with context sharing afterwards.
https://doc.qt.io/qt-6/qsurfaceformat.html#setDefaultFormat
However, Qt3DWindow sets the default QSurface format during its initialization which is causing the following warning message:
This PR is a tentative to work around this issue by reimplementing Qt3dWindow. The new implementation lets qgis main.cpp configure the default Qsurface format.
Added benefit of this approach is that it should also make it possible to overlay widgets on top of the 3d viewport which is currently not possible using Qt3dWindow.