[PyQt] Subclass pyuic4 generated file...

NoursBleu noursbleu at free.fr
Fri Jan 16 17:40:52 GMT 2009


Hi all !

I've created a simple QDialog with Qt-Designer 4, named ImageDialog and  only 
containing a pushButton called pushButton.
The file name is test.ui

Next I've used pyuic4 wich created a file named Ui_test.py containing :

#############BEGIN#####################

from PyQt4 import QtCore, QtGui

class Ui_ImageDialog(object):
    def setupUi(self, ImageDialog):
        ImageDialog.setObjectName("ImageDialog")
        ImageDialog.resize(400, 300)
        self.pushButton = QtGui.QPushButton(ImageDialog)
        self.pushButton.setGeometry(QtCore.QRect(280, 20, 96, 25))
        self.pushButton.setObjectName("pushButton")

        self.retranslateUi(ImageDialog)
        QtCore.QMetaObject.connectSlotsByName(ImageDialog)

    def retranslateUi(self, ImageDialog):
        ImageDialog.setWindowTitle(QtGui.QApplication.translate("ImageDialog", 
"Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("ImageDialog", 
"PushButton", None, QtGui.QApplication.UnicodeUTF8))

###############END####################

Now, I'm trying to subclass this to modify pushButton text or connect 
pushButton to a function. I've read PyQt4 Guide and created this :

##############BEGIN#################

import sys
from PyQt4 import QtCore, QtGui
from Ui_test import Ui_ImageDialog

class ImageDialog(QtGui.QDialog):
    def __init__(self):
        QtGui.QDialog.__init__(self)
        self.ui = Ui_ImageDialog()
        self.ui.setupUi(self)
        
	#Modifications
        self.ui.pushButton.setText("MyNewText")


#Display Form
app = QtGui.QApplication(sys.argv)
window = QtGui.QDialog()
ui = Ui_ImageDialog()
ui.setupUi(window)

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

###############END#################

My dialog is displayed, but pushButton has no text modification.
Same thing if I want to connect pushButton to a function.
I don't know how to reach Dialog widgets attributes.
Could you help me ?
THANX !



More information about the PyQt mailing list