Display image in Qt to fit label size

Actually there is a very simple solution for this problem. There are two things you should modify:

  1. Set the scaled content to true (mentioned above)
  2. Set the label’s size policy to ignored

    QLabel lblImage;
    
    lblImage->setPixmap( QPixmap( "big_image.jpg" ) );
    
    lblImage->setScaledContents( true );
    
    lblImage->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
    

If the lblImage is resizing automatically, the image will stretch to the size of the label.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)