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

Image resizing upon a resize event. Postpone after the event?



  • Hello community ! I have spend some effort trying to optimize my application for loading large images. So far so good I dropped my memory usage from 150 mb down to depending on the actual size needed (4-5 mb). But I am facing another problem with this workaround. Basically here is what I am currently doing.

    void roomWindow::resizeEvent(QResizeEvent *evt)
    {   
       QImageReader reader (":/IMG/Images/Window/Backdrop.png");
       reader.setScaledSize(this->size());
       QPalette palette;
       palette.setBrush(QPalette::Background, reader.read());
        this->setPalette(palette);
        QDialog::resizeEvent(evt);
    }
    

    Backdrop.png is a large image 4k res, I am using the QImageReader as stated from the documentation it is the most efficient way for the memory. In my QDialog constructor (which is triggered when a button is pressed) I set the backdrop image to what the .size of the dialog is (which is taking some time as it's scaling, loading and setting the palette), then after a resize event occur for that said Dialog I execute the code snipped above. The problem I am facing is the amount of time for my said Dialog to unfreeze from all the stuff going with it and the time for the construction which is about lets say a second ?

    Is there a more optimal solution for the problem? I can sacrifice the construction time, but at least can I make the window resizing feel more "snappy". I guess that I can do it somehow postponing the loading and scaling of the image after the resizing of the window is finished, but I don't know how.

    I have also noticed that when ever the said dialog is "generated" the resize event is triggered after the construction which leads to doing the thing twice before any visible Dialog appears !

    Please allow my ignorance as I am just starting with the framework.

    Thanks for your time and consideration.
    Regards.


  • Lifetime Qt Champion

    Hi
    See here :)
    https://forum.qt.io/topic/113693/containing-picture-window-resizing-stops-every-few-pixels

    The trick is to paint the scaled image with paintEvent as you will get MANY resizeEvent
    so its faster to use paintEvent to limit the number of times it runs.
    It should at least make "the window resizing feel more "snappy""



  • Thanks, now I got my solution!


Log in to reply