Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Update QGraphicsScene only in a specified area
Thomas Stein last edited by Thomas Stein
I've been struggling with this for a while now.
I have a QGraphicsView and in it a QGraphicsScene. At runtime I am trying to update only specific areas in the QGraphicsScene but it doesnt quiet work. Here is some minimal code showing the problem:
import sys from PyQt5 import QtWidgets as qtw from PyQt5 import QtGui as qtg from PyQt5 import QtCore as qtc class MainWindow(qtw.QMainWindow): def __init__(self): super().__init__() self.scene = qtw.QGraphicsScene() self.scene.setSceneRect(0,0,720,720) self.view = qtw.QGraphicsView() self.view.setViewportUpdateMode(qtw.QGraphicsView.NoViewportUpdate) self.view.setScene(self.scene) self.setCentralWidget(self.view) self.show() def mousePressEvent(self, a0: qtg.QMouseEvent) -> None: self.scene.addLine(0, 0, 720, 720) self.scene.update(0, 0, 720, 720) #<--- This does not work but should work #self.scene.update() <--- This works for some reason if __name__ == '__main__': app = qtw.QApplication(sys.argv) mainWindow = MainWindow() sys.exit(app.exec())
For some reason, calling update() without parameter on the scene object works, but when i specify the area to be updated, it doesnt work. Any ieads?
Note: I set the views viewportupdatemode to NoViewportUpdate because the docs state the following:
QGraphicsView will never update its viewport when the scene changes; the user is expected to control all updates. This mode disables all (potentially slow) item visibility testing in QGraphicsView, and is suitable for scenes that either require a fixed frame rate, or where the viewport is otherwise updated externally.
This is what I want, since i only want to update specific areas almost every frame, not the whole scene over and over again. When is set the Viewportmode to something else, it seems like update() calls on the QgraphicsScene object within the QGraphicsView are being ignored
Please don't post the same question multiple times.
Closing this one