title: How can I resize image as fast as QLabel does?
body: <p>I am trying to write a Qt-based application that displays and manipulates images.<br>
  I want the image to be always expanded to the size of the window keeping its aspect ratio.<br>
  Unfortunately QLabel does not have an option to keep aspect ratio of the attached pixmap.<br>
  So I wrote a custom widget and implemented resizeEvent() and paintEvent() to resize the image<br>
  and paint it:</p>
  
  <pre><code>   class MyLabel : public QWidget
     {
       Q_Object
  
     public:
       MyLabel(): pixmap("test.tif") {} 
  
     protected:
       void resizeEvent(QResizeEvent *event)
       {
         pixmap_scaled = pixmap.scaled(size(), Qt::KeepAspectRatio);
       }
  
       void paintEvent(QPaintEvent *event)
       {
         QPainter p(this);
         p.drawPixmap(0, 0, pixmap_scaled);
         p.end();
       }
  
     private:
       QPixmap pixmap, pixmap_scaled;
     };  
  </code></pre>
  
  <p>But the image was not resized as smoothly as QLabel does.</p>
  
  <p>Then I take a look at the paintEvent function of QLabel in qlabel.cpp to see how it   displays the pixmap.<br>
  There it seems that the pixmap is once converted to a QImage and scaled to the window   size,<br>
  and then converted again to a QPixmap.<br>
  I was a bit surprised because converting between   QPixmap and QImage is an expensive operation<br>
  according to Qt reference manual, but I tried rewriting paintEvent() of my widget to do the same thing<br>
  as QLabel::paintEvent(). Then the resizing became much slower as expected.    </p>
  
  <p>I wonder why resizing of QLabel is so fast. Is it the benefit of "implicit data sharing"?<br>
  Of course It is impossible to just copy paintEvent() of QLabel to my class because private data<br>
  such as "d pointer" cannot be accessed. </p>
  
  <p>Any help would be appreciated.</p>