Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Panning a QImage using translate
Forum Updated to NodeBB v4.3 + New Features

Panning a QImage using translate

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ankush205
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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 ?

      157

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved