Using QWebEngineView seems to disrupt QPropertyAnimation smoothness, even if QWebEngineView has just been destroyed
-
I have a problem with QPropertyAnimation when QWebEngineView is used in the same QMainWindow.
If I create 15 QPropertyAnimation (animate QGraphicsRectItem),
and in the same time I use a QWebEngineView, then animations become very slow.I have created a demo (to compile yourself), with minimum usefull source code : https://media.nperf.com/files/misc/src_sandbox_web_animation.zip
Tests made with one QMainWindow :
After creating QWebEngineView, if I kill it, the problem continues.
If I use QTimer loop instead of QPropertyAnimation, the problem is the same.
Tests made with two QMainWindow :
If I embed the QWebEngineView in an external window (new QMainWindow), then animations become smooth again.
This new QMainWindow is not the same QMainWindow where QPropertyAnimations are running.However, this is not an acceptable solution for me, but this shows that there is a resource that is shared between QWebEngineView and QPropertyAnimations,
if and only if the QWebEngineView was created in the same QMainWindow.So I wonder :
- Did I kill the QWebEngineView correctly ?
- Is there a way to seperate QWebEngineView threads from QMainWindow ?
- Or any other solution...
Environment context :
This problem exist with two environments, win10/Qt5.15.2 and Mac/Qt5.15.0.
But does not exist with ubuntu20/Qt5.12 and ubuntu18/Qt5.9.2.
Reproductible code example (Code description of demo shared):
- The QPropertyAnimation change size of a QGraphicsRectItem :
class AnimationBarItem : public QObject, public QGraphicsRectItem { Q_OBJECT Q_PROPERTY(QRectF rect READ rect WRITE setRect) ... } class AnimationBar : public QGraphicsView { Q_OBJECT ... AnimationBarItem *bar = nullptr; } void AnimationBar::setPourcent(qreal pourc){ QPropertyAnimation *animation = new QPropertyAnimation(bar, "rect"); animation->setDuration(200); animation->setStartValue(QRect(0, 0, 0, mH)); animation->setEndValue(QRect(0, 0, ww,mH)); animation->start(); }
- The QWebEngineView is created as follow :
mWebEngineView = new QWebEngineView();//can't link to this, for compatibility with my project mWebEnginePage = new QWebEnginePage(mWebEngineView); mWebEnginePage->setView(mWebEngineView); mWebEngineView->setUrl(QUrl("http://www.google.com"));
- then add in QMainWindow with method :
mLayoutForBrowse=new QVBoxLayout(ui->ZONE_webview); mLayoutForBrowse->addWidget(mWebEngineView);
- Or, in a new QMainWindow :
<br>And not in the same QMainWindow like previous point, with :
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
- killing webview :
void MainWindow::killWebView(bool is){ if (mWebEngineView!=nullptr) mWebEngineView->stop(); mWebEngineView->deleteLater(); mLayoutForBrowse->deleteLater(); mWebEnginePage->deleteLater(); mWebEngineView=nullptr; mLayoutForBrowse=nullptr; mWebEnginePage=nullptr; }