from PyQt5 import QtGui, QtCore, QtWidgets

app = QtWidgets.QApplication([])

v = QtWidgets.QGraphicsView()
s = QtWidgets.QGraphicsScene()
v.setScene(s)
v.show()

v.resize(640, 480)

# this path disappears when its starting point crosses the view edge
path = QtGui.QPainterPath()
path.moveTo(0, 0)
path.lineTo(0.5, 1e-7)
path.lineTo(1, 1)

# this path also disappears
path2 = QtGui.QPainterPath()
path2.moveTo(0.5, 1e-7)
path2.lineTo(1, 1)

# this path does not disappear
path3 = QtGui.QPainterPath()
path3.moveTo(0, 0)
path3.lineTo(0.5, 1e-7)

pen1 = QtGui.QPen(QtGui.QColor(255, 0, 0))
pen1.setWidth(0)

pen2 = QtGui.QPen(QtGui.QColor(0, 255, 0))
pen2.setWidth(0)

pen3 = QtGui.QPen(QtGui.QColor(0, 0, 255))
pen3.setWidth(0)

pi1 = QtWidgets.QGraphicsPathItem(path)
pi1.setPen(pen1)

pi2 = QtWidgets.QGraphicsPathItem(path2)
pi2.moveBy(0.1, 0)
pi2.setPen(pen2)

pi3 = QtWidgets.QGraphicsPathItem(path3)
pi3.moveBy(0.1, 0)
pi3.setPen(pen3)

s.addItem(pi1)
s.addItem(pi2)
s.addItem(pi3)

y = -0.5e-7


def update():
    global y
    rect = QtCore.QRectF(-.1, y, 1, 2e-7)
    v.setSceneRect(rect)
    v.fitInView(rect, QtCore.Qt.IgnoreAspectRatio)
    y += 0.01e-7
    if y > 1.2e-7:
        y = -0.5e-7


timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(20)

app.exec_()
