Important: Please read the Qt Code of Conduct -

Panoramic view in QGraphicsView

  • hi, i have a panoramic 360° picture which i put on a QGraphicsScene and show with a QGraphicsView. I'd like to be able to pan it to the right or left infinitley and it would always repeat the image on the borders.

    Like this: ```

    but only in one vertical direction ..

  • push push push

  • Lifetime Qt Champion

    I am not sure you can make 360 images with QGraphicsView in any sane manner.
    I think you will need some opengl to do it.

  • the 360° view is already projected on a 2d image, i just need to find a way to stitch the ends together while panning over the view.

  • Lifetime Qt Champion

    and the ends are already stitch friendly?

  • @mrjj yes

  • Lifetime Qt Champion

    I never made such view.
    What if u have a QGraphicsItem with a paint event
    that paints a subset of the full image.
    Lets just say 300,300. You then slide the drawn area when
    camera is moved. When it reaches the end of full image, you
    must then copy the slice from the start of the full image so it wraps
    over. And the reverse in the reverse direction.
    I dont know how image really look so might not be possible but if image is
    already sort of projected then it could work.

  • my solution: i placed the same picture twice (next to eachother) in the QGraphicsScene. Then i derived from QGraphicsView and implemented the following functions:

    void CustomGraphicsView::mouseMoveEvent(QMouseEvent *pEvent) {
        if (lastPos_ != pEvent->pos() && isLeftMouseButtonDown_) {
        lastPos_ = pEvent->pos();
    void CustomGraphicsView::mousePressEvent(QMouseEvent *pEvent) {
        if (pEvent->buttons() == Qt::LeftButton) {
            isLeftMouseButtonDown_ = true;
    void CustomGraphicsView::mouseReleaseEvent(QMouseEvent *pEvent) {
        if (pEvent->buttons() == Qt::LeftButton) {
            isLeftMouseButtonDown_ = false;
    void CustomGraphicsView::adjustViewport() {
        // allows infinite horizontal panning
        int w = imageSize_.width();
        QRectF r = mapToScene(viewport()
        // panning to the right
        if (r.x() + r.width() > w * 2) {
            centerOn(QPointF(r.x() - w + r.width() / 2,
                r.y() + r.height() / 2));
        // panning to the left
        if (r.x() < 2) {
            centerOn(QPointF(w + r.width() / 2 , r.y() + r.height() / 2));

    Every time the right mouse button is held and the mouse is moved the viewport is adjusted. if the view comes to close to the left or right side it uses QGraphicsView::centerOn to jump to the other picture. So the illusion of a infinitley pannable panorama picture is created.

  • Lifetime Qt Champion

    thank you. very interesting.

Log in to reply