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 8995571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:38:16+00:00 2026-06-15T23:38:16+00:00

I created a label in my main window and its size is set to

  • 0

I created a label in my main window and its size is set to 200x300px. now on a button click i need to view a image in it. here is the slot function of the button.

 void MainWindow::function1(){
QImage img;
img.loadFromData("test.jpg");
img = img.scaled(200, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation);
label->setPixmap(QPixmap::fromImage(img));
}

the problem is this compiles without errors, but not displaying the image. insted when the button is pressed it says QImage::scaled: Image is a null image in the IDE
im new in qt. I would be very thankful for any advice.

thank you

  • 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-06-15T23:38:17+00:00Added an answer on June 15, 2026 at 11:38 pm

    Using a QImage is necessary if you are processing images outside of your GUI thread. Also the loadFromData() function looks like it is used for passing in a large array of bytes, not the name of the file.

    Here is how I would do it with a QPixmap.

    QPixmap pix;
    
    bool loaded = pix.load("test.jpg");
    
    if(loaded == false)
    {
        label->setText("Failed to load test.jpg from" + QDir::currentPath());
    }
    else
    {
        pix = pix.scaled(200, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        label->setPixmap(pix);
    }
    

    You may also want to replace 200 and 300 with label->width() and label->height(). Scaling a pixmap this way looks the best, but you can also just set the pixmap and then use label->setScaledContents(true)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a label using Interface Builder, and now I want to set the
I have an image label created like this. Painter painter = new Painter() {
I created a form with a label, textbox and a button. In the form
I have created a user control (link) which has a label and a button.
I've successfully created an NSCollectionView and added a label to the view prototype in
In my app i have created one custom class for Label.Now i want to
I have created a RibbonButton and given its Tooltip this way <ribbon:RibbonButton Label=My Label
i've created a select button with 3 option <%= f.label :prioridad %><br/> <%= f.select
I have created an iframe which contains the label, powered by MyWebsite.site The iframe
Hi i want to create a multiline Custom Label in Blackberry I have created

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.