第一種方案
使用 QPixmap 的 transformed 函數來實現旋轉,這個函數默認是以圖片中心為旋轉點,不能設置旋轉的中心點,使用如下:
QMatrix matrix;
matrix.rotate(45);
QLabel *Label= new QLabel();
Label->setPixmap(QPixmap(“:/images.png”).transformed(matrix, Qt::SmoothTransformation));
該段程序實現的效果是使圖片順時針旋轉 45 度。
第二種方案
使用 QPainter 這位“畫家”,示例程序如下:
void Widget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QPixmap disc(":/disc.png");
/* 碟機轉動 */
if(imageRotate++ == 360)
imageRotate = 0;
/* 設定旋轉中心點 */
painter.translate(130,150);
/* 旋轉的角度 */
painter.rotate(imageRotate);
/* 恢復中心點 */
painter.translate(-130,-150);
/* 畫圖操作 */
painter.drawPixmap(40,60,180,180, disc);
}
參考自:www.cnblogs.com/findumars/p/5574332.html