Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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: ```
    http://www.airpano.ru/files/Brasil-Rio-de-Janeiro/2-2

    
    but only in one vertical direction ..


  • push push push


  • Lifetime Qt Champion

    hi
    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.
    http://www.student.nada.kth.se/~nv91-gta/OpenGL/panorama/



  • 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

    @ck_ee
    ok.
    and the ends are already stitch friendly?



  • @mrjj yes


  • Lifetime Qt Champion

    @ck_ee
    oK.
    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_) {
            adjustViewport();
        }
    
        lastPos_ = pEvent->pos();
        QGraphicsView::mouseMoveEvent(pEvent);
    }
    
    void CustomGraphicsView::mousePressEvent(QMouseEvent *pEvent) {
        if (pEvent->buttons() == Qt::LeftButton) {
            isLeftMouseButtonDown_ = true;
        }
        QGraphicsView::mousePressEvent(pEvent);
    }
    
    void CustomGraphicsView::mouseReleaseEvent(QMouseEvent *pEvent) {
        if (pEvent->buttons() == Qt::LeftButton) {
            isLeftMouseButtonDown_ = false;
        }
        QGraphicsView::mouseReleaseEvent(pEvent);
    }
    
    void CustomGraphicsView::adjustViewport() {
        // allows infinite horizontal panning
        int w = imageSize_.width();
        QRectF r = mapToScene(viewport()
            ->geometry()).boundingRect();
    
        // 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

    @ck_ee
    thank you. very interesting.


Log in to reply