PDA

View Full Version : QtDesigner and Python



mshemuni
23rd September 2012, 10: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.

wysota
23rd September 2012, 11:11
Have a look at QGraphicsScene::addPixmap()

By the way, do not change the file generated by pyuic. Instead subclass the class and add your code to your subclass.

mshemuni
23rd September 2012, 12:23
Have a look at QGraphicsScene::addPixmap()

By the way, do not change the file generated by pyuic. Instead subclass the class and add your code to your subclass.

Well. I'm a newbie.
Can you fix my code and sen it back?
So I can use it as a sample.;)
I think there will be two files and I must import my code file to pyuic generated file ha? But how? :D

d_stranz
23rd September 2012, 18:29
I think there will be two files and I must import my code file to pyuic generated file ha?

I can't help you with Python code, but as Wysota said, don't touch the pyuic file. Import the pyuic generated file into *your* custom code file, not the other way around. This is exactly the same as C++ programmers do with the MOC- and UIC-generated files.

wysota
23rd September 2012, 18:49
I think there will be two files and I must import my code file to pyuic generated file ha? But how? :D

Most probably using the "import" statement :)

mshemuni
24th September 2012, 21:21
Most probably using the "import" statement :)

What about triggers and getting parameters from functions?
Please make a small, silly, pathetic example for me. (:

wysota
25th September 2012, 00:11
What about triggers and getting parameters from functions?
I have no idea what you mean.


Please make a small, silly, pathetic example for me. (:

See the attachment.

mshemuni
25th September 2012, 09:38
I have no idea what you mean.
At first thank you very much for example.

But I meant triggers like Onclick, OnMouseMove, OnMouseDown and bla bla.
For example can you make a calculator that can print sum of two numbers.
Something like this:

8245
8244
But you said do not change pyuic4 generated file. How can I do the example above with your method?

wysota
25th September 2012, 10:38
But I meant triggers like Onclick, OnMouseMove, OnMouseDown and bla bla.
For example can you make a calculator that can print sum of two numbers.
See attachment.