QT图片旋转

  1、使用QPixmap的transformed函数旋转,这个函数默认是以图片中心为旋转点,不能随意设置旋转点,使用如下:

QMatrix leftmatrix;
 leftmatrix.rotate(180);

QLabel *pLabel= new QLabel();
pLabel->setPixmap(QPixmap(“:/images/img.png”).transformed(leftmatrix,Qt::SmoothTransformation));

   2、使用QPainter类

void Dialog::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QPixmap pix;
pix.load("images/img.png");
painter.translate(50,50); //让图片的中心作为旋转的中心
    painter.rotate(90); //顺时针旋转90度
    painter.translate(-50,-50); //使原点复原
    painter.drawPixmap(0,0,100,100,pix);
}

猜你喜欢

转载自blog.csdn.net/lengyuezuixue/article/details/80896875