QImage Rotation



  • Hey guys,

    I'm trying to create a customized qdial by making my own paintevent to display and rotate a QImage:

    void Knob::paintEvent(QPaintEvent *)
    {
    QPainter painter(this);

    QImage knobPix("C:\\Users\\Roham\\Documents\\Buzz\\knob.png");
    
    QMatrix rot;
    
    qDebug() << ((double)(this->value())/(double)(this->maximum()))*270;
    
    rot.rotate((double)((double)(this->value())/(double)(this->maximum())*270));
    
    QImage out = knobPix.transformed(rot);
    
    qDebug() << QString::number(this->width()) << "," << QString::number(this->height());
    
    painter.drawImage(QPoint(0,0),out);
    

    }

    This code doesnt rotate my QImage properly, it distorts and moves it around (it doesnt rotate the image around its center). It seems to be working fine for angles that are multiples of 90 degrees. I've tried translating the image to its width/2, height/2 and back afterwards with the same results.

    Any tips or advice you guys would have will be much appreciated!!

    Thanks a bunch!


  • Moderators

    @rtavakko Wouldn't it be easier and probably faster to use a set of pictures each one rotated relative to previous one? Then simply paint one after another (similar to animated GIF).



  • @rtavakko Don't use QImage::transformed, instead set transform to your QPainter


  • Qt Champions 2016


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.