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. QLabel not showing image correctly
Qt 6.11 is out! See what's new in the release blog

QLabel not showing image correctly

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • E Offline
    E Offline
    elephanten
    wrote on last edited by
    #1

    Hello everybody,

    I have written an application, that links statically to the plug-in, that is of my own code. Everything is done in Qt. My plug-in has KDevice class, which has *QWidget face() function. The widget this function returns has QLabel on it with an image. The image is taken from resource inside plug-in. This face gets added to some layout of the app on start-up after loading the plug-in.

    The problem here is that the image in QLabel gets resized to whatever size Qt wants. Especially if my file is portrait of landscape type, not a rectangle. My goal is to make Qt keep the size of the image.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      There are hasWidthForHeight and hasHeightForWidth functions for QLabel. When you do need to set the constraints, subclass the QLabel and redefine those functions to keep the aspect ratio

      Greetz, Jeroen

      1 Reply Last reply
      0
      • E Offline
        E Offline
        elephanten
        wrote on last edited by
        #3

        Thanks, but maybe I should use another widget?

        1 Reply Last reply
        0
        • E Offline
          E Offline
          elephanten
          wrote on last edited by
          #4

          Ha! I got it, my fault. I was setting QLabel's image like that:
          @
          ui->label->setPixmap(pic->scaleToHeigth(200));
          @

          instead of correct
          @
          ui->label->setPixmap(pic);
          @

          May this post be helpful to someone else :)

          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