Q多边形变换

发布于 2024-12-25 05:19:26 字数 923 浏览 3 评论 0原文

需要动态变换多边形顶点直到原点 0,0(而不是中心)。

我有多边形( 8x64 )(带有预定义的顶点):

QPolygonF cursor;
cursor << QPointF(-4, 32); 
cursor << QPointF(-4, -32);
cursor << QPointF(4, -32);
cursor << QPointF(4, 32);

然后我绘制它并用作光标:

QPixmap pixmap( cursor.boundingRect().width()+1, cursor.boundingRect().height()+1 );
pixmap.fill( QColor( Qt::black) );

QPixmap alpha = pixmap.createMaskFromColor(QColor( Qt::black ),Qt::MaskOutColor);
pixmap.setAlphaChannel( alpha );

QPainter painter( &pixmap );
painter.setPen( QPen( Qt::green) );

// move to center, because polygon coordinated starts from center
painter.translate(cursor.boundingRect().width()/2, cursor.boundingRect().height()/2 );
painter.drawPolygon( cursor );

setCursor( pixmap );

但是单击鼠标后,我的鼠标位置位于该多边形的中心,这是正常且符合逻辑的。

问题,如何动态变换多边形(变换矩阵等)到 0,0 原点并在鼠标单击左上坐标(而不是中心)后获取?

Need to transform polygon vertexes on the fly till origin point 0,0 (instead of center).

I have polygon ( 8x64 ) (with predefined vertex):

QPolygonF cursor;
cursor << QPointF(-4, 32); 
cursor << QPointF(-4, -32);
cursor << QPointF(4, -32);
cursor << QPointF(4, 32);

Then I draw it and use as cursor:

QPixmap pixmap( cursor.boundingRect().width()+1, cursor.boundingRect().height()+1 );
pixmap.fill( QColor( Qt::black) );

QPixmap alpha = pixmap.createMaskFromColor(QColor( Qt::black ),Qt::MaskOutColor);
pixmap.setAlphaChannel( alpha );

QPainter painter( &pixmap );
painter.setPen( QPen( Qt::green) );

// move to center, because polygon coordinated starts from center
painter.translate(cursor.boundingRect().width()/2, cursor.boundingRect().height()/2 );
painter.drawPolygon( cursor );

setCursor( pixmap );

But after mouse click, I have mouse position at center of this polygon, this is normal and logical.

Question, how to transform polygon on the fly ( transform matrix or such ) to 0,0 origin point and get after mouse click top, left coordinates (instead of center) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文