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
Servers for Qt installer are currently down

Not able to rotate a QPixmap

Scheduled Pinned Locked Moved General and Desktop
rotation
2 Posts 2 Posters 1.8k Views 2 Watching
  • 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 11 Apr 2015, 06:27 last edited by houmingc 4 Nov 2015, 06:36
    #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
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 11 Apr 2015, 11:21 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

      2/2

      11 Apr 2015, 11:21

      • Login

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