Trying to explain my problem with more details.
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/s..._animation.zip
sandbox_webview_qpropertyanimation.png
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):
1. The QPropertyAnimation change size of a QGraphicsRectItem :
{
Q_OBJECT
Q_PROPERTY(QRectF rect READ rect WRITE setRect
) ...
}
{
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();
}
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();
}
To copy to clipboard, switch view to plain text mode
2. 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"));
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"));
To copy to clipboard, switch view to plain text mode
3. then add in QMainWindow with method :
mLayoutForBrowse->addWidget(mWebEngineView);
mLayoutForBrowse=new QVBoxLayout(ui->ZONE_webview);
mLayoutForBrowse->addWidget(mWebEngineView);
To copy to clipboard, switch view to plain text mode
4. Or, in a new QMainWindow :
<br>And not in the same QMainWindow like previous point, with :
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
To copy to clipboard, switch view to plain text mode
5. killing webview :
void MainWindow::killWebView(bool is){
if (mWebEngineView!=nullptr) mWebEngineView->stop();
mWebEngineView->deleteLater();
mLayoutForBrowse->deleteLater();
mWebEnginePage->deleteLater();
mWebEngineView=nullptr;
mLayoutForBrowse=nullptr;
mWebEnginePage=nullptr;
}
void MainWindow::killWebView(bool is){
if (mWebEngineView!=nullptr) mWebEngineView->stop();
mWebEngineView->deleteLater();
mLayoutForBrowse->deleteLater();
mWebEnginePage->deleteLater();
mWebEngineView=nullptr;
mLayoutForBrowse=nullptr;
mWebEnginePage=nullptr;
}
To copy to clipboard, switch view to plain text mode
Bookmarks