Resize image to show in Qt



  • Hello, I want to show some pictures in Qt, but their size will not match the size that I intend to present in the Qt widget, so how can I show an image resizing its original size to fit the widget's size?


  • Qt Champions 2016

    hi and welcome
    Pixmap class has scaled function which returns a scaled copy.

    QPixmap p; // load pixmap
    // get label dimensions
    int w = label->width();
    int h = label->height();

    // set a scaled pixmap to a w x h window keeping its aspect ratio
    label->setPixmap(p.scaled(w,h,Qt::KeepAspectRatio);


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.