mshemuni
23rd September 2012, 09:28
Hi everyone.
I have two problems with QtDesigner.
I'm using QtDesigner and converting file to PyQt with this code:
pyuic4 -x [input] -o [output]
I'm adding functions to output file and make it do something.
For example I have a graphicsView and a line Edit and two buttons.
Ok. When you clicked on first button a dialog open file appears and let you select an image file to view on graphicsview.
I want fill Line Edit with my name when second button clicked. But I want to send my name as a parameter to class.
But I can't display image and sent parameter to a class. This is my code:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'exa.ui'
#
# Created: Sun Sep 23 11:25:27 2012
# by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(665, 575)
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(30, 530, 88, 27))
self.pushButton.setObjectName("pushButton")
self.lineEdit = QtGui.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(220, 530, 421, 27))
self.lineEdit.setObjectName("lineEdit")
self.graphicsView = QtGui.QGraphicsView(Form)
self.graphicsView.setGeometry(QtCore.QRect(20, 10, 621, 451))
self.graphicsView.setObjectName("graphicsView")
self.pushButton_2 = QtGui.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(550, 470, 88, 27))
self.pushButton_2.setObjectName("pushButton_2")
self.retranslateUi(Form)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.changeText)
QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL("clicked()"), self.displayImage)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.transla te("Form", "Change text", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit.setText(QtGui.QApplication.translate ("Form", "awdaddwa", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.trans late("Form", "Add picture", None, QtGui.QApplication.UnicodeUTF8))
def displayImage(self):
filename=QtGui.QFileDialog.getOpenFileName(Form,"ADd file...","./",("Image (*.gif *.jpeg *.jpg *.png)"))
#Display image in GraphicsView I can't do this part.
def changeText(self):
self.lineEdit.setText(QtGui.QApplication.translate ("Form", "Muhammed SHEMUNI", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
Sorry for bad English.
I have two problems with QtDesigner.
I'm using QtDesigner and converting file to PyQt with this code:
pyuic4 -x [input] -o [output]
I'm adding functions to output file and make it do something.
For example I have a graphicsView and a line Edit and two buttons.
Ok. When you clicked on first button a dialog open file appears and let you select an image file to view on graphicsview.
I want fill Line Edit with my name when second button clicked. But I want to send my name as a parameter to class.
But I can't display image and sent parameter to a class. This is my code:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'exa.ui'
#
# Created: Sun Sep 23 11:25:27 2012
# by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(665, 575)
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(30, 530, 88, 27))
self.pushButton.setObjectName("pushButton")
self.lineEdit = QtGui.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(220, 530, 421, 27))
self.lineEdit.setObjectName("lineEdit")
self.graphicsView = QtGui.QGraphicsView(Form)
self.graphicsView.setGeometry(QtCore.QRect(20, 10, 621, 451))
self.graphicsView.setObjectName("graphicsView")
self.pushButton_2 = QtGui.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(550, 470, 88, 27))
self.pushButton_2.setObjectName("pushButton_2")
self.retranslateUi(Form)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.changeText)
QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL("clicked()"), self.displayImage)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.transla te("Form", "Change text", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit.setText(QtGui.QApplication.translate ("Form", "awdaddwa", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.trans late("Form", "Add picture", None, QtGui.QApplication.UnicodeUTF8))
def displayImage(self):
filename=QtGui.QFileDialog.getOpenFileName(Form,"ADd file...","./",("Image (*.gif *.jpeg *.jpg *.png)"))
#Display image in GraphicsView I can't do this part.
def changeText(self):
self.lineEdit.setText(QtGui.QApplication.translate ("Form", "Muhammed SHEMUNI", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
Sorry for bad English.