Panning a QImage using translate



  • I wanted a basic image viewer with zoom and pan. Initially i tried with frame and by using scroll area and flabel resize,
    But my requirements have changed so i wanted to keep my frame size same with no scroll area.simply and fixed size frame and zoom and pan in it

    My label properties are set as
    label->setscaledcontents(false);
    label->resize(800,800);
    lbel->setsizepolicy(ignored;ignored);

    I was able to zoom using image->scaled();

    now i was trying to pan by using mouse move event,so i am writing my mouse move event

    void mouseMoveEvent(QMouseEvent *event)
    {
    if(pan){
    QTransform trans;
    trans=trans.translate(10.2,10.2);
    *image=image->transformed(trans);
    displayimage();

    m_panStartX = event->x();
    m_panStartY = event->y();
    event->accept();
    return;
    }

    m_panStartX = event->x();
    m_panStartY = event->y();
    event->ignore();
    }
    But the image is not getting panned.Any solutions?


  • Moderators

    Hi,

    Please use code tags '@@' while posting your code.
    Have you subclassed the label ? and there reimplemented mouseMoveEvent ? Normally QTransform is used in paintEvent.
    When you do transform operations like scale,translate etc.. you need to do "setTransform":http://qt-project.org/doc/qt-5/qpainter.html#setTransform in paintEvent so that transformations take effect. Can you provide more details ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.