Qt直接旋转一张图片,会发生错位。所以应该修正一下。
定时旋转一张图片,修正位置后,很好。旋转控件类似
QTimer* m_pRotatePointerTimer = new QTimer(this);
connect(m_pRotatePointerTimer, SIGNAL(timeout()), SLOT(OnEventRotatePointer()));
m_pRotatePointerTimer->start(1000);
void OnEventRotatePointer()
{
QPixmap pix(":/main-icon/image/main-icon/14.2.png");
static int rat = 0;
rat = rat >= 360 ? 0 : rat + 30;
int imageWidth = pix.width();
int imageHeight = pix.height();
QPixmap temp(pix.size());
temp.fill(Qt::transparent);
QPainter painter(&temp);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
painter.translate(imageWidth / 2, imageHeight / 2); //让图片的中心作为旋转的中心
painter.rotate(rat); //顺时针旋转90度
painter.translate(-(imageWidth / 2), -(imageHeight / 2)); //使原点复原
painter.drawPixmap(0, 0, pix);
painter.end();
m_zeroUI.label_pointer->setPixmap(temp);
}