Qpainter.rotate() 问题 - qgis
我正在定制 QuantumGIS,它使用 Qt 的 Qpainter 进行绘制和绘制...
我试图在画布上绘制一条折线,该折线将通过消息队列进行更新...绘制非常好...但是在折线或多边形中我作为更新获得的对象还包括用于对象旋转的角度场。 问题是,当我尝试在 qpainter 使用 Painter.rotate() 方法绘制折线之前旋转线条时,线条旋转得很好,但绘制的线条的位置发生了变化..并且它在每次缩放和Qgis 画布的平底锅.. 在设置painter.rotate()之前,我保存画家状态,并在绘制之后再次恢复其状态,我相信这类似于OpenGL的push/popMatrix函数。 Qpainter的保存恢复功能与opengl的push/popMatrix功能类似吗?
这是一个代码片段:
p->save();
//p->rotate(45);
p->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
p->drawPolyline( pa );
p->restore();
感谢帮助。 谢谢。
I am customising QuantumGIS that uses Qt's Qpainter to draw and paint...
I am trying to draw a polyline on the canvas that is coming as a update through message queues..the draw is very fine...but in the polyline or polygon objects that i get as an update also include an angle field that is to be used for rotation of an object.
The problem is that when i try to rotate the line just before the polyline is drawn by the qpainter using painter.rotate() method,the line is rotated fine but the position of the line drawn changes..and it changes at every zoom and pan of the Qgis canvas..
Before setting painter.rotate() i am saving the painter state and after drawing- again restoring its state which i believe is analogous to OpenGL's push/popMatrix functions.
Does the Qpainter's save restore functions work similar to push/popMatrix functions of opengl??
here is a code snippet:
p->save();
//p->rotate(45);
p->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
p->drawPolyline( pa );
p->restore();
Help is appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你最好的选择是在 QGIS Mailing 中提出这个问题列表
your best bet would be to ask this question in the QGIS Mailing List
阅读文档,您会发现 QPainter::save() 仅“保存”当前画家的状态”。 它不会重置转换。 您的问题是因为原始变换矩阵与您自己的缩放或旋转混合。 您的代码片段太少,无法理解绘画的上下文,但我认为您需要在折线绘画之前适当地重置或修改转换,也许使用 QPainter::setTransform()。
我还建议阅读 QPainter 文档 中的坐标转换部分,以及尝试相关示例。
Read the documentation and you see that QPainter::save() only "Saves the current painter state". It does not reset the transformation. Your problem was because the original transformation matrix gets mixed with your own scale or rotate. Your code snippet is too minimal to understand the context of the painting, but I reckon you need to reset or modify the transformation suitably before your polyline painting, perhaps using QPainter::setTransform().
I recommend also reading Coordinate Transformations section in QPainter documentation, as well as trying the related example.