annapac.blogg.se

Image resize aspect ratio
Image resize aspect ratio






  1. #Image resize aspect ratio how to#
  2. #Image resize aspect ratio code#

(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) Pixmap = pixmap.scaled(256, 128, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) (_translate("MainWindow", "TextLabel"))Ĭlass Test(QtWidgets.QMainWindow, Ui_MainWindow): Self.verticalLayout_2.addLayout(self.horizontalLayout) Self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget) SpacerItem = QtWidgets.QSpacerItem(40, 20,, ) boBox = QtWidgets.QComboBox(self.centralwidget) Self.label = QtWidgets.QLabel(self.centralwidget) Self.verticalLayout = QtWidgets.QVBoxLayout() Self.verticalLayout_2.setObjectName("verticalLayout_2") Self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget) Self.centralwidget = QtWidgets.QWidget(MainWindow) To scale the image down as you wanted and keep the ratio between the two elements, you need to set setScaledContents(True) like this: from PyQt5 import QtCore, QtGui, QtWidgets Return super(Test, self).eventFilter(widget, event) If event.type() = and widget is self.LogoLabel: Self._logo = QtGui.QPixmap('res/image.png') The dynamic resizing can then be handled using an event-filter, like this: class Test(QtWidgets.QMainWindow, Ui_ZEBRA): Self.verticalLayout_3.setAlignment(QtCore.Qt.AlignTop)

#Image resize aspect ratio code#

This can all be done in Qt Designer, but your example code can also be fixed manually like this: self.LogoLabel = QtWidgets.QLabel(self.centralwidget) Also, some properties of the label need adjustment so that it can resize itself freely. You firstly need to change the layout so that it uses alignment rather than expanding spacers to keep the label at the top left corner. Such a basic thing that is nowhere to be found?

#Image resize aspect ratio how to#

(QtGui.QPixmap('res/image.png'))ĮDIT: Weirdly enough, i could not find a single working example on how to use an image in a QLabel and scale its size while changing the window size, while also keeping the aspect ratio. nuBar_tText(_translate("ZEBRA", "About."))Ĭlass Test(QtWidgets.QMainWindow, Ui_ZEBRA): nuBar_tText(_translate("ZEBRA", "Test Accesstoken")) nuBar_tText(_translate("ZEBRA", "Enter Accesstoken")) Self.ComboBox_tItemText(3, _translate("ZEBRA", "id")) Self.ComboBox_tItemText(2, _translate("ZEBRA", "displayName")) Self.ComboBox_tItemText(1, _translate("ZEBRA", "Use all devices")) Self.ComboBox_tItemText(0, _translate("ZEBRA", "ip")) tWindowTitle(_translate("ZEBRA", "ZEBRA")) nuBar_TestToken = QtWidgets.QAction(ZEBRA) nuBar_EnterToken = QtWidgets.QAction(ZEBRA)

image resize aspect ratio

Self.verticalLayout_4.addLayout(self.horizontalLayout) Self.TextInput_tObjectName("TextInput_Devices") Self.TextInput_Devices = QtWidgets.QPlainTextEdit(self.centralwidget) Self.verticalLayout_3.addWidget(self.ComboBox_InputType) Self.ComboBox_tObjectName("ComboBox_InputType") Self.ComboBox_InputType = QtWidgets.QComboBox(self.centralwidget) Self.verticalLayout_3.addItem(spacerItem) SpacerItem = QtWidgets.QSpacerItem(20, 40,, ) Self.verticalLayout_3.addWidget(self.LogoLabel) Self.LogoLabel = QtWidgets.QLabel(self.centralwidget) Self.verticalLayout_3.setObjectName("verticalLayout_3") Self.verticalLayout_3 = QtWidgets.QVBoxLayout() Self.horizontalLayout = QtWidgets.QHBoxLayout()

image resize aspect ratio

Self.verticalLayout_4.setObjectName("verticalLayout_4") Self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.centralwidget) Self.centralwidget = QtWidgets.QWidget(ZEBRA)

image resize aspect ratio

from PyQt5 import QtCore, QtWidgets, QtGui I added a stretcher and used a QLabel to display the image, and then added the file via (QtGui.QPixmap('res/image.png')), so i do not understand what i need to change in order to get the image to always be nice and small in the top left corner.Ī test example, in case the question wasnt clear enough - the image i need is 1000x710px large. I already found that you seem to be able to do this via selecting the layout and changing the LayoutStretch to something like 1,3 - this worked in the designer, however, when i inserted my image in the code, it did not respect it and blew the layout out of proption again. How can i do this, either in the designer, or in the code? So that i can add a small image in the top left corner that wont be gigantic or too small, but always in nice relation to the size of the window. I want the ratio of the left object and the right object to always be like this:








Image resize aspect ratio