title: How to zoom and scroll in QGLWidget
body: <p>In a project where I use QGLWidget to create my own image viewer, I'm trying to add zooming and scrolling feature in displaying large images but I get a problem where the image is cut and cannot be wider than it's original size or the panel size.</p>
  
  <p>Here i set up the viewport and glScalef. In implementing scrolling, I subclass QAbstractScrollArea and pass the coordinate of scrollbars into a variable.</p>
  
  <pre><code>// scrollOffset has the coordinates of horizontal and vertical scrollbars
  // this-&gt;width() and this-&gt;height() are panel size
  glViewport(0 - scrollOffset.x(), 0 + scrollOffset.y(), this-&gt;width(),  this-&gt;height());
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0, this-&gt;width(),  this-&gt;height(),  0);  // flip the y axis
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  
  // if zoomFactor value is 1.0 means no zooming
  glScalef(zoomFactor, zoomFactor, 1.0);
  
  glClear(GL_COLOR_BUFFER_BIT);
  </code></pre>
  
  <p>Render the image:</p>
  
  <pre><code>glBindTexture( GL_TEXTURE_2D, texId );
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.bits());    
  glBegin(GL_QUADS);    
  // text coords are flipped in y axis
  // width and height are image's original size
  glTexCoord2d(0,1); glVertex3d(0,     0,      0);
  glTexCoord2d(1,1); glVertex3d(width, 0,      0);
  glTexCoord2d(1,0); glVertex3d(width, height, 0);
  glTexCoord2d(0,0); glVertex3d(0,     height, 0);    
  glEnd();
  </code></pre>
  
  <p>in image below, i scroll down the image but the displayed image cannot be taller than the panel's height</p>
  
  <p><img src="https://i.stack.imgur.com/t5PRA.png" alt="enter image description here"></p>