PDA

View Full Version : Can't get QLineEdit textEdited signal to work



Michael Druckenmiller Sr
12th April 2012, 18:52
Using Python 2.7.2 and pyQT... This is the only forum I can get to from work. (Thank You NMCI!)

I have a pop-up with 10 Buttons and a QLineEdit.

I did not set any Masks or Validators when I constructed the GUI in QTDesigner.

The "returnPressed" signal works.

I can not get the "textEdited" signal to work at all, period.

I come from a VB-6 background and the reference to (const QString&) in void textEdited (const QString&) has me completely "snowed".

What I want to do is get the length of the entered text as it changes and update a characters-remaining count for the user.

Of course if I can't get a signal emitted when each character is typed, I can't do that...

Help! :)

THANKS!



class Oper_Comnt(QDialog, ui_OpComnt.Ui_OpComnt):
"""
This Class creates an instance of the ui_OpComnt.Ui_OpComnt pop-up
Dialog used for Displaying/Receiving Operator Comments.
"""
def __init__(self, text, NumChars=255, parent=None):
super(Oper_Comnt, self).__init__(parent)
self.__index = 0
self.setupUi(self)
self.setModal(True)
self.NumChars = NumChars

# Set up events for Button Clicks
Selection=[]
for i in range(10):
Selection.append(getattr(self, "Comment_%d" %(i+1)) )
self.connect(Selection[i],SIGNAL("clicked()"),
self.comment_click)

self.connect(self.lineEdit,SIGNAL("returnPressed()"),self.usr_enter)

self.connect(self.lineEdit,SIGNAL("textEdited()"),self.new_char)

ChrisW67
13th April 2012, 07:02
In a C++ environment running your code would emit a warning about the connect() call telling you that the signal does not exist: I do not know if PyQt does similar.

The QLineEdit::textEdited() passes a QString value to any connected slot: the new text in the line edit. The signal signature would be

SIGNAL("textEdited(QString)") and the receiving slot needs to handle the string parameter.