Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-47844

[Regression] QLabel scaledContents stretches its pixmap way beyond its size

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2: Important P2: Important
    • None
    • 5.5.0
    • None
    • Mac OSX 10.10 (retina)
    • macOS

      Try the following code. It will show that the pixmap on the label with scaled contents. You can enlarge the pixmap and see that when its width is 256 (2x as much) it will finally display properly onto the label. Interestingly it is only a problem in width, not in height.
      I suppose that could be related to retina display

      #include <QtGui>
      #include <QHBoxLayout>
      
      int main(int argc, char **argv) {
          QApplication app(argc, argv);
          QPixmap pix(128, 128);
          pix.fill(Qt::black);
          {
              QPainter p(&pix);
              QLinearGradient gradient(0, 0, 128, 128);
              gradient.setColorAt(0, Qt::red);
              gradient.setColorAt(1, Qt::blue);
              p.fillRect(0,0,128,128, gradient);
          }
      
          QWidget w;
          QHBoxLayout l;
          w.setLayout(&l);
      
          QLabel lbl1;
          lbl1.setPixmap(pix);
          lbl1.setScaledContents(false);
          l.addWidget(&lbl1);
      
          QLabel lbl2;
          lbl2.setPixmap(pix);
          lbl2.setScaledContents(true);
          l.addWidget(&lbl2);
      
          w.show();
          return app.exec();
      }
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            sorvig Morten Sørvig
            thierryb Thierry Bastian
            Votes:
            9 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes