Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6846141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:35:09+00:00 2026-05-27T00:35:09+00:00

I use a QLabel to display the content of a bigger, dynamically changing QPixmap

  • 0

I use a QLabel to display the content of a bigger, dynamically changing QPixmap to the user. It would be nice to make this label smaller/larger depending on the space available. The screen size is not always as big as the QPixmap.

How can I modify the QSizePolicy and sizeHint() of the QLabel to resize the QPixmap while keeping the aspect ratio of the original QPixmap?

I can’t modify sizeHint() of the QLabel, setting the minimumSize() to zero does not help. Setting hasScaledContents() on the QLabel allows growing, but breaks the aspect ratio thingy…

Subclassing QLabel did help, but this solution adds too much code for just a simple problem…

Any smart hints how to accomplish this without subclassing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:35:09+00:00Added an answer on May 27, 2026 at 12:35 am

    In order to change the label size you can select an appropriate size policy for the label like expanding or minimum expanding.

    You can scale the pixmap by keeping its aspect ratio every time it changes:

    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));
    

    There are two places where you should add this code:

    • When the pixmap is updated
    • In the resizeEvent of the widget that contains the label
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use QLabel s to display some data in this format username:.....Erich
Use case: user clicks the link on a webpage - boom! load of files
use this website a lot but first time posting. My program creates a number
Use Case When a user goes to my website, they will be confronted with
Why this code show me a window without image? I try to use QByteArray
Use Case: End-User searches for something and an ArrayCollection is returned with Result objects.
This is a question about Qt library, not about Web design. For QLabel and
I have a QLabel without any text but with a QPixmap image. I can
The Widget we should use to show pictures is a QLabel. we can do
Use: The user searches for a partial postcode such as 'RG20' which should then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.