[PyQt] Subclass pyuic4 generated file...
Nahuel Defossé
nahueldefosse at yahoo.com.ar
Sun Jan 18 18:20:32 GMT 2009
El Friday 16 January 2009 15:44:14 NoursBleu escribió:
> 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 !
>
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Try to modify self.pushButton instead of self.ui.pushButton.
The UI is set to self, not to self.ui. Take a closer look to what does setupUi
to its parameter.
Nahuel
More information about the PyQt
mailing list