Reputation: 33395
I've gotten into a muddle setting up a QPainter transformation. I've read the Qt Documentation but brainfog is getting in the way.
void MyWidget::paintEvent (QPaintEvent *) {
QPainter painter (this);
// ...
I want to render a scene which is described in logical coordinates. The scene includes a "stage" which is the rectangle to be rendered. The stage is specified in logical coordinates. The widget should have a viewport (is that the correct terminology?) which
In the above situation the stage would be described by something like
QRectF stage_rect (QPointF(0.2,5.1), QPointF(6.5,1.9));
if I set up the transformation and call
painter.drawText (1.2, 2.2, "abc");
it should appear in the lower-left of the widget as indicated above -- that is, logical coordinates increase upwards, the full height of the stage is shown in the widget, and the stage is cropped horizontally to preserve aspect ratio (although it is possible that the widget is too wide/short, in which case the stage would be vertically cropped).
What transformation should I apply to the QPainter to fit the window tightly into the stage?
Upvotes: 1
Views: 1869
Reputation: 2444
Qt's coordinate system has the positive direction down and to the right rather than up and to the right, which is what you're wanting. To do that, set your Y scale factor in the transform to -1 and X scale factor to 1; that will flip the Y coordinates but not the X. However, if you apply that transformation to the painter, I believe you'll end up with your text upside down. What you probably want instead is to transform the coordinates and then pass the transformed coordinates to the painter.
Upvotes: 2