Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to scale QImage or QPixmap to fit the parent Width X Height?



  • Hello,
    I am trying to scale a PNG ( which I am not sure is right ) to match the parent WxH. Here is my code:
    @
    ...
    QImage test3(":/resources/images/test3.png");
    test3 = test3.scaled(width, height, Qt::IgnoreAspectRatio);
    ...
    myScene->setBackgroundBrush(QBrush(test3));
    myScene->setSceneRect(QRectF(0,0,width,height));
    @
    Where "width" and "height" are passed from parent class who calls this code. The result is shown here:
    https://www.flickr.com/photos/heatblazer/15460475363/
    I want the screen to be filled with the background image. As in the examples with Qt::IgnoreAspectRatio is shown - it should fill to max width and height. Also - can I use SVG to achieve the effect without losing quality of the image? And what are the costs for rendering SVG?


Log in to reply