1
Recently I’m learning how to use the PyQt4, but a doubt arose in the use of the line of code to modify the scale of an image:
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(743, 510)
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(20, 430, 85, 27))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.foto = QtGui.QLineEdit(Form)
self.foto.setGeometry(QtCore.QRect(20, 390, 700, 27))
self.foto.setObjectName(_fromUtf8("Diretorio"))
self.label = QtGui.QLabel(Form)
self.label.setGeometry(QtCore.QRect(30, 26, 671, 341))
self.label.setText(_fromUtf8(""))
self.label.setObjectName(_fromUtf8("label"))
self.horizontalSlider = QtGui.QSlider(Form)
self.horizontalSlider.setGeometry(QtCore.QRect(120, 430, 601, 18))
self.horizontalSlider.setMaximum(255)
self.horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
self.horizontalSlider.setObjectName(_fromUtf8("horizontalSlider"))
self.label_2 = QtGui.QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(380, 450, 71, 17))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.retranslateUi(Form)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.abrirfoto)
#self.horizontalSlider.valueChanged.connect(self.threshold)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Testando", None))
self.pushButton.setText(_translate("Form", "Abrir", None))
self.label_2.setText(_translate("Form", "Threshold", None))
def abrirfoto(self):
img = self.foto.text()
self.label.setPixmap(QtGui.QPixmap(img))
QtGui.QPixmap.scaled(671,341,0,0)
And returns the error:
Typeerror: Arguments Did not match any overloaded call: QPixmap.scaled(int, int, Qt.AspectRatioMode aspectRatioMode=Qt.IgnoreAspectRatio, Qt.TransformationMode transformMode=Qt.FastTransformation): first argument of unbound method must have type 'QPixmap' QPixmap.scaled(QSize, Qt.AspectRatioMode aspectRatioMode=Qt.IgnoreAspectRatio, Qt.TransformationMode transformMode=Qt.FastTransformation): first argument of unbound method must have type 'QPixmap'
You can’t make Scaled "loose" in the code. You have to call Scaled on an existing pixmap. You tried
QtGui.QPixmap(img).scaled(671,341,0,0)? (I don’t know if you can chain like this in Pyqt. if you can’t, assign it to a variable, apply Scaled and then put it on the label)– Bacco
I created another variable and applied Scaled, it worked here. thanks for the help =)
– D.Cavalcante
Post below as answer to your solution, explain what has changed and mark as accepted, so legal closes the question and can help other people.
– Bacco