title: Use window/viewport to flip QPainter y-axis
body: <p>I'm using Qt 4.7 QPainter to draw some polygons, etc into a widget. I am hoping to alter the coordinate system so that (0,0) is at the center of my widget, and the x/y axis behave in a standard "Cartesian" way (ie. y increases going "up" and decreases going "down"). In other words, I want the coordinates to be "math"-like not "computer graphics"-like, if you know what I mean. :-)</p>
  
  <p>I'm trying to do this using setViewport() and setWindow() rather than do the math myself, as it would be nice to be able to just call the draw methods directly with my coordinates.</p>
  
  <p>Here's what I've got so far:</p>
  
  <pre><code>// Setup coordinates
  double screenWidth = width();
  double screenHeight = height();
  
  double windowWidth = 100.0;
  double windowHeight = (screenHeight / screenWidth) * windowWidth;
  
  painter.setViewport(0, 0, screenWidth, screenHeight);
  painter.setWindow(-(windowWidth / 2.0), -(windowHeight / 2.0), windowWidth, windowHeight);
  
  // Draw stuff
  painter.setPen(Qt::NoPen);
  painter.setBrush(Qt::blue);
  painter.drawRect(-10, -10, 20, 20);
  </code></pre>
  
  <p>Now this works just fine, in that it draws a nice blue square in the middle of the screen. The problem is, I have to say that the upper left corner is (-10, -10). I'd like to be able to make it (-10, 10), as that is what it would be in Cartesian coords.</p>
  
  <p>I tried messing with setWindow/setViewport to get this "y-axis flip", but to no avail. This seems like a really easy/basic thing to do, but after scouring the Qt docs and the web, I can't figure it out!</p>
  
  <p>Thanks,<br>
  Chris</p>