[PyQt] Beginners - signal - slots - question

Jochen Georges jochengeorges at yahoo.de
Fri Dec 21 10:51:39 GMT 2007


Hello,

i finished my first "Hello-World"-PyQt-program sucessfully, 
but not my second. 

I googled for an example, but did not find any, so maybe you can give me a 
hint.

There is a QLineEdit-element and a QLabel-element.
When te user finished editing the QLineEdit, the text should be changed and  
then displayed in the QLabel.

Which is the right QLineEdit-Signal?
	the action should start when return is pressed, but the
	signal "returnPressed" has no parameter "QString"
	and
	textChanged(QString) or textEdited(QString) react on every single input
How do i place my own method, that changes the text?

Thanks for any hint.

beste gruesse
jochen

this is my code:

BackwardsWriter.py:

# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        
MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,471,330).size()).expandedTo(MainWindow.minimumSizeHint()))

        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.lineEdit = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit.setGeometry(QtCore.QRect(40,40,401,51))
        self.lineEdit.setObjectName("lineEdit")

        self.lb_Info = QtGui.QLabel(self.centralwidget)
        self.lb_Info.setGeometry(QtCore.QRect(40,120,401,51))
        self.lb_Info.setAlignment(QtCore.Qt.AlignCenter)
        self.lb_Info.setObjectName("lb_Info")

        self.lb_ergebnis = QtGui.QLabel(self.centralwidget)
        self.lb_ergebnis.setGeometry(QtCore.QRect(30,200,401,51))
        self.lb_ergebnis.setAlignment(QtCore.Qt.AlignCenter)
        self.lb_ergebnis.setObjectName("lb_ergebnis")
        MainWindow.setCentralWidget(self.centralwidget)

        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0,0,471,29))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)

        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        #QtCore.QObject.connect(self.lineEdit, 
QtCore.SIGNAL("textChanged(QString)"), self.lb_ergebnis, 
QtCore.SLOT("setText(QString)"))
        
#QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL("returnPressed()"),self.blabla)
        #
        # ?????????
        #
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def blabla(self):
        string_source = "Hallo Welt"
        string_drain = ""
        count = len(string_source)
        while count > 0:
            string_drain = string_drain + string_source[count-1]
            count -= 1
        print string_drain

    def retranslateUi(self, MainWindow):
        
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", 
None, QtGui.QApplication.UnicodeUTF8))
        
self.lb_Info.setText(QtGui.QApplication.translate("MainWindow", "Rückärts 
sieht das so aus:", None, QtGui.QApplication.UnicodeUTF8))
	
__________________________________

run.py :

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
from PyQt4 import QtCore, QtGui

from BackwardsWriter import Ui_MainWindow

class MyForm(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = MyForm()
    myapp.show()






More information about the PyQt mailing list