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. Resize image to show in Qt
QtWS25 Last Chance

Resize image to show in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 708 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.
  • P Offline
    P Offline
    Pedro_Monteiro
    wrote on last edited by
    #1

    Hello, I want to show some pictures in Qt, but their size will not match the size that I intend to present in the Qt widget, so how can I show an image resizing its original size to fit the widget's size?

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

      hi and welcome
      Pixmap class has scaled function which returns a scaled copy.

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

      1 Reply Last reply
      1

      • Login

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