需要动态转换多边形顶点直到原点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原点并在鼠标点击顶部,左侧坐标(而不是中心)后得到?