[PyKDE] Signal Interactions

Bob Parnes rparnes at megalink.net
Mon Jun 23 00:57:01 BST 2003


Hello,

Be warned that I am new at coding pyqt, and no doubt the problem has a simple
solution. The attached demo illustrates it: Pressing the <Enter> key after
typing text into the edit box also triggers the 'clicked' signal of the
pushbutton. Comments in the code describe a workaround, but this disrupts
the tab sequence.

What I am missing escapes me, so any help is appreciated. Thanks.

bp


-- 
Bob Parnes
rparnes at megalink.net
-------------- next part --------------
#!/usr/bin/env python

# If the user enters text into the LineEdit widget and then presses the <Enter>
# key to process the text, this also triggers the 'clicked' signal of the 
# PushButton widget, calling the buttonClick slot. In a setup with more than one
# pushbutton, the first one in the tab order is activated by the 'returnPressed'
# signal of the edit widget.

# One workaround is to create a button with no attached signal or slot, make it
# the first pushbutton in the tab order, and hide it.

import sys
from qt import *

class Form1(QDialog):
    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)

        if not name:
            self.setName("Form1")

        self.LineEdit5 = QLineEdit(self,"LineEdit5")
        self.LineEdit5.setGeometry(QRect(20,10,144,28))

        self.PushButton7 = QPushButton(self,"PushButton7")
        self.PushButton7.setGeometry(QRect(20,50,138,38))

        self.languageChange()

        self.resize(QSize(202,119).expandedTo(self.minimumSizeHint()))

        self.connect(self.LineEdit5,SIGNAL("returnPressed()"),self.editReturn)
        self.connect(self.PushButton7,SIGNAL("clicked()"),self.buttonClick)

    def languageChange(self):
        self.setCaption(self.tr("Form1"))
        self.PushButton7.setText(self.tr("PushButton7"))

    def editReturn(self):
        print "Form1.editReturn(): Not implemented yet"

    def buttonClick(self):
        print "Form1.buttonClick(): Not implemented yet"

if __name__ == "__main__":
    a = QApplication(sys.argv)
    QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
    w = Form1()
    a.setMainWidget(w)
    w.show()
    a.exec_loop()


More information about the PyQt mailing list