title: QPainter rotation. Where to translate?
body: <p>I'm working on a new project in Qt, using QPainter to draw a QWidget.
  The problem is, when I try to rotate QPainter the text I want to draw rotates out of my QWidget.
  I know how to solve the problem in general, but somehow I couldn't figure it out until now.
  I have to translate my QPainter, in order to position my text right for the rotation, but I don't know how to specify that point to where I should translate my coordinate system. 
  My code without the translation:</p>
  
  <pre><code>QPainter painter;
  
  float width = 40;
  float height = 200;
  
  float rangeMin = 0;
  float rangeMax = 100;
  
  float progress = 80;
  QString format("%1/%2");
  int alignmentHorizontal = Qt::AlignHCenter;
  int alignmentVertical = Qt::AlignVCenter;
  
  int fontSize = 12;
  QColor backgroundColor = Qt::green;
  QColor fontColor = Qt::black;
  
  QFont font("Arial", fontSize);
  QBrush backgroundBrush(backgroundColor);
  QBrush transparentBrush(QColor(0,0,0,0));
  QRect boundingRect = QRect(0, 0, width, height);
  
  painter.begin(this);
  
  painter.setFont(font);
  painter.setPen(fontColor);
  
  painter.drawRect(boundingRect);
  
  float rectX = 0;
  float rectY = 0;
  float rectWidth = width;
  float rectHeight = (float)height/(qAbs(rangeMin)+rangeMax)*progress;
  int textRotation = 90;
  
  painter.setBrush(backgroundBrush);
  QRectF rect = QRectF(rectX, rectY, rectWidth, rectHeight);
  painter.drawRect(rect);
  
  //This is the text I want to rotate, while keeping it centerd horizontally and vertically in boundingRect.
  //painter.translate(x, y);
  painter.rotate(textRotation);
  painter.drawText(boundingRect, alignmentHorizontal | alignmentVertical, QString(format).arg(progress).arg(rangeMax));
  
  painter.end();
  </code></pre>
  
  <p>Could you please explain how to calculate that point I need?</p>
  
  <p>Thanks for your help! :)</p>
  
  <p>Edit:</p>
  
  <p>I edited my code like this:</p>
  
  <pre><code>painter.save();
  painter.translate(width/2, height/2);
  painter.rotate(textRotation);
  painter.drawText(boundingRect, alignmentHorizontal | alignmentVertical, QString(format).arg(progress).arg(rangeMax));
  painter.restore();
  </code></pre>
  
  <p>But it's still rotating out of my drawing area.
  Any ideas?</p>