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. Qt label image display always has different size from original image

Qt label image display always has different size from original image

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 556 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.
  • L Offline
    L Offline
    Ludicrous Gray
    wrote on last edited by Ludicrous Gray
    #1

    I have a problem with the image size displayed on label. It seems there are a fixed maximum size for the image's height even when the displayed image should be larger (check image below). This resulted the image getting cut which I don't want. I already tried to change the size of the Qpixmap ratio but the one that change is the size of the image but not the frame of the image. Here is the code that I use to display the image

    from PyQt5 import QtWidgets,QtGui,QtCore
    from mainwindow import Ui_MainWindow
    import numpy as np 
    import sys
    import cv2
    import matplotlib.pyplot as plt
    
        class ApplicationWindow(QtWidgets.QMainWindow):
            def __init__(self):
                super(ApplicationWindow, self).__init__()
    
                self.ui = Ui_MainWindow()
                self.ui.setupUi(self)
                self.ui.extractLightbtn.clicked.connect(lambda:self.extractLight(self.ui.browseLine.text()))
    
            def extractLight(self,filePath):
                #function to do extraction using model
                if filePath != "":
                   self.oriImage = QtGui.QPixmap(filePath)
                   self.oriResImage = self.oriImage.scaled(256, 256, QtCore.Qt.KeepAspectRatio)
                   self.ui.oriDisplay.setPixmap(self.oriResImage)
    

    Screenshot from 2020-06-10 14-15-49.png

    As you can see on screenshot above. The right image got cut on neck to below and What I want is to display it to the same size as the image on the left. The original image size is 178x218 and since I allocate 256x256 space it should be enough for it. I do suspect the problem is on the designer part. Maybe someone can give me guidance on how to build it, I would be grateful

    Screenshot from 2020-06-10 16-36-34.png

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Try setting the scaledContents property of QLabel to true

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      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