I have a PyQt5 application which shows a window containing some items and a ruler on both sides. For example:

The structure of the application is as follows:
The widget containing the QGraphicsView places it in a QSplitter which is placed inside the QHBoxLayout of the widget.
The QGraphicsView has a QGraphicsScene which is added using setScene . The size of the scene is set using:
self.setSceneRect(QtCore.QRectF(self.contentsRect()))
The scene contains the two rulers which are QGraphicsRectItem with custom paint methods. These are added using the addItem method of the scene.
When the user right clicks the view and drags their mouse the scene location is updated. This is done by storing the initial mouse position at the mousePressEvent, and translating the view during the mouseMoveEvent. The scene is moved using the setSceneRect method.
The issue that I have is that if the user moves their mouse too quickly, the rulers will get outside the drawing region and will not be redrawn untill the user moves the other direction to capture them again.
What I've tried:
- Calling
update,prepareGeometryUpdatesandinvalidateon the rulers. - Calling the
renderandrepaintmethods on theQGraphicsViewevery time a move is executed.
What works:
I can get it to update by creating a QPainter and calling the paint event of the rulers manually when the view is updated. However, this raises a bunch of PyQt warnings.
Code Example:
Due to the large amount of code involved for a minimal working example, I tried to write it as clear as possible above. Please let me know if anything is unclear .