I am a beginner with Qt in Python.
I create simple from using Qt Designer.
1) generate python code: pyuic4 -o mygui.py mygui.ui
2) write code:
import sys
from PyQt4 import QtCore, QtGui
from mygui import Ui_MainWindow
class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.abc)
def abc(self):
input = self.ui.lineEdit.text()
self.ui.label_2.setText(input)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())
It works, but is possible to write QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.abc)
simpler?
Not a complete answer but surely mentionable: Code completion does not work for dynamic objects. You could of course still use
self.pushButton.clicked.connect(self.abc)
instead of
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.abc)
but there won't be any code completion for self.pushButton.clicked.*
(This also answers the question https://stackoverflow.com/a/28270242/4537483 )