Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Image resizing upon a resize event. Postpone after the event?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 661 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    l000p
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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""

      1 Reply Last reply
      2
      • L Offline
        L Offline
        l000p
        wrote on last edited by
        #3

        Thanks, now I got my solution!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved