PDA

View Full Version : Writing text on a transformed QPainter



Cruz
28th April 2012, 17:15
Hello!

Whenever I use QPainter to draw something on a widget, I usually transform the coordinate system to a mathematical one, where the origin is either in the middle or the bottom left corner and the positive direction of the Y axis is pointing upwards. This makes it very easy for me to use logical coordinates to visualize objects that come from somewhere in my application, and probably many people do the same. When it comes to writing text on the widget, however, I'm facing an ugly problem. If I just use the currently applied transform, the text is upside down. And the only way I see to work around this problem is to first draw all my objects on the screen, then reset the transform of the QPainter, and then apply the transform manually to the coordinates of each drawText() command, such that the text itself is not flipped upside down. This is quite annoying. Does anyone know a better way?

Thanks
Cruz