Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Not able to rotate a QPixmap

Not able to rotate a QPixmap

Scheduled Pinned Locked Moved General and Desktop
rotation
2 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by houmingc
    #1

    Not able to rotate a picture 360 degree, smoothly.
    page5_label= new QLabel();
    page5_label->setPixmap(QPixmap(":/cartopView.png"));

                 Layout_page5 = new QVBoxLayout(this);
                 Layout_page5->addWidget(page5_label);
                 QTimer::singleShot(60000,this,&MainWindow::pictureRotate);
    
    
      void MainWindow::pictureRotate()
    

    {
    while(1){

                QPixmap ship(":/cartopView.png");
                QPixmap rotate(ship.size());
    
                QPainter p(&rotate);
                p.setRenderHint(QPainter::Antialiasing);
                p.setRenderHint(QPainter::SmoothPixmapTransform);
                p.setRenderHint(QPainter::HighQualityAntialiasing);
                p.translate(rotate.size().width() / 2, rotate.size().height() / 2);
                p.rotate(counter);
                p.translate(-rotate.size().width() / 2, -rotate.size().height() / 2);
    
                p.drawPixmap(0,0,ship);
                p.end();
    
                page5_label->setPixmap(rotate);
         }
    }
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      First of all while(1) in a UI thread is a very bad idea. This effectively freezes your ui.
      A quick fix is to add qApp->processEvents(); at the end of the loop, but that's really just a band-aid.

      Instead of the loop I would suggest to start a timer at reasonable interval (not shorter than an average monitor can actually display). You wouldn't need the processEvents hack with that.
      Another thing is that you're loading an image, setting painter hints and recreating two pixmaps and a painter every step of the animation. That's terribly inefficient. Take them all out of the loop and just redo the painting, not the whole shabang.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved