Qpainter.rotate () question - qgis

I am setting up QuantumGIS which uses Qt Qpainter for drawing and painting ...

I am trying to draw a polyline on a canvas that comes as an update via message queues. Draw is very good ... but the polyline or polygon objects that I receive as an update also have an angle field that should be used to rotate the object. The problem is that when I try to rotate the line directly in front of the polyline drawn by the qpainter method using the painter.rotate () method, the line rotates fine, but the position of the line drawn changes ... and it changes with every scaling and the canvas pan Qgis .. Before setting painter.rotate (), I save the state of the animal and after painting - restoring its state again, which I believe is similar to the push / popMatrix OpenGL functions. Does the Qpainter restore functionality support functions similar to the push / popMatrix opengl functions?

Here's a snippet of code:

p->save();
  //p->rotate(45);
  p->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
  p->drawPolyline( pa );
  p->restore();

      

Help is appreciated. Thanks.

+1


a source to share


2 answers


Read the documentation and you can see that only QPainter :: save () saves the saved painting state. This is not a reset conversion. Your problem was that the original transformation matrix is ​​mixing with your own scale or rotating. Your code snippet is too small to understand the context of the picture, but I suppose you need to reset or change the transform in front of your polyline accordingly, perhaps using QPainter :: SetTransform () .



I also recommend reading the Coordinate Conversion section in the QPainter documentation , and trying the corresponding example .

+1


a source


the best way to ask this question is in the QGIS Mailing List



0


a source







All Articles