Reputation: 41
I am making a simple browser using PyQt5 and Python. I need to start a loading gif using
self.movie.start()
self.movie.stop()
but I need to call self.movie.stop()
after the web page is completely loaded.
Upvotes: 0
Views: 514
Reputation: 243973
You have to use the loadStarted and loadFinished signals to start and stop the animation:
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets
class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.view = QtWebEngineWidgets.QWebEngineView()
self.label = QtWidgets.QLabel(alignment=QtCore.Qt.AlignCenter)
self.movie = QtGui.QMovie("loading.gif")
self.label.setMovie(self.movie)
lay = QtWidgets.QVBoxLayout(self)
lay.addWidget(self.view, stretch=1)
lay.addWidget(self.label, stretch=0)
self.view.loadStarted.connect(self.movie.start)
self.view.loadFinished.connect(self.movie.stop)
self.view.load(QtCore.QUrl("https://www.qt.io"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
Upvotes: 2