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. Shrink widget to fit it's new contents
QtWS25 Last Chance

Shrink widget to fit it's new contents

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 770 Views
  • 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.
  • 4 Offline
    4 Offline
    4k53l1
    wrote on last edited by
    #1

    I'm making a test program that displays an image and you can change that image. I have the image in QScrollArea and I want it to shrink when smaller image is chosen. I think the code explains it little better:
    @
    image->load(filename);
    QImage scaledImage = *image;
    // my function for resizing the image to fit the area
    resizeImage(&scaledImage, imageScrollArea->width(), imageScrollArea->height());

    imageLabel->setPixmap(QPixmap::fromImage(scaledImage));
    imageLabel->adjustSize();

    // here i think i should somehow update the imageLabel

    // this is supposed to resize the scroll area to fit the new image
    imageScrollArea->setMinimumHeight(scaledImage.height());
    imageScrollArea->adjustSize();

    // if i call sleep(5) here i can still see the old image for five seconds
    // which is why the previous two functions don't shink the scroll area
    @

    I'm not sure if this is confusing so i'll explain little more. First I resize the new image to fit the scroll area. Then since the image ratio is kept there is some left over space in the scroll area and I want to shrink that away.

    This is what it now looks like after replacing the image (the scroll area is marked with a green background)
    !https://i.imgur.com/Rm9iDOD.png(iamge)!

    I could do this with setFixedSize (because it doesn't care about the child widget which is the old image) but I can't use that since I want the image to be resizable by the user if he resizes the window.

    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