[newbie] Python and Qt4 Designer
Vincent Vande Vyvre
vincent.vandevyvre at swing.be
Wed Jul 11 20:59:11 EDT 2012
On 11/07/12 17:37, Jean Dubois wrote:
> I'm trying to combine python-code made with QT4 designer with plain
> python statements like
> file = open("test","w")
> Can anyone tell me what I have to add to the following code just to
> open a file when clicking on the load-button and closing it by
> clicking on the save button.
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> # Form implementation generated from reading ui file 'test.ui'
> #
> # Created: Wed Jul 11 17:21:35 2012
> # by: PyQt4 UI code generator 4.8.3
> #
> # WARNING! All changes made in this file will be lost!
>
> from PyQt4 import QtCore, QtGui
>
> try:
> _fromUtf8 = QtCore.QString.fromUtf8
> except AttributeError:
> _fromUtf8 = lambda s: s
>
> class Ui_Form(object):
> def setupUi(self, Form):
> Form.setObjectName(_fromUtf8("Form"))
> Form.resize(400, 300)
> self.widget = QtGui.QWidget(Form)
> self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25))
> self.widget.setObjectName(_fromUtf8("widget"))
> self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
> self.horizontalLayout.setMargin(0)
>
> self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
> self.pushButton_2 = QtGui.QPushButton(self.widget)
> self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
> self.horizontalLayout.addWidget(self.pushButton_2)
> self.pushButton = QtGui.QPushButton(self.widget)
> self.pushButton.setObjectName(_fromUtf8("pushButton"))
> self.horizontalLayout.addWidget(self.pushButton)
>
> self.retranslateUi(Form)
> QtCore.QMetaObject.connectSlotsByName(Form)
>
> def retranslateUi(self, Form):
> Form.setWindowTitle(QtGui.QApplication.translate("Form",
> "Form", None, QtGui.QApplication.UnicodeUTF8))
> self.pushButton_2.setText(QtGui.QApplication.translate("Form",
> "Save file", None, QtGui.QApplication.UnicodeUTF8))
> self.pushButton.setText(QtGui.QApplication.translate("Form",
> "Load file", 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_())
>
>
> thanks in advance
> jean
Connect the signal clicked of your's buttons to your's functions.
self.pushButton.clicked.connect(self.my_func)
Here's all the truth:
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_signals_slots.html
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte+7
<https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager>
More information about the Python-list
mailing list