简体   繁体   中英

set label size as big as QPixmap image

I have an label that displays an image, however the image is cut off since its size is bigger than the label, I have tried self.logo_buttons.SetScaledContents(True) but this only resizes my image to fit in the label.

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class GUI(QMainWindow):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.initUI()

    def initUI(self):
        self.logo_button = QtWidgets.QLabel(self)
        self.logo_button.setPixmap(QtGui.QPixmap('image.png'))
        self.logo_button.setScaledContents(True)


def window():
    app = QApplication(sys.argv)
    root = GUI()

    root.show()
    sys.exit(app.exec_())


window()

What you have to do is adjust the size of the QLabel using adjustSize():

self.logo_button = QtWidgets.QLabel(self)
self.logo_button.setPixmap(QtGui.QPixmap('image.png'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM