It uses the following trick:
if (event->button() == Qt::MidButton) {
setDragMode(QGraphicsView::ScrollHandDrag);
// create a new mouse event that simulates a click of the left button instead of the middle button
QMouseEvent mouseEvent (event->type(), event->pos(), Qt::LeftButton, Qt::LeftButton, event->modifiers());
QGraphicsView::mousePressEvent(&mouseEvent);
}
That is, when midbutton is down, set the dragging mode and simulate a leftbutton press. The mouse release handler is similar and is omitted here.