Q多边形变换
需要动态变换多边形顶点直到原点 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论