PDA

View Full Version : PyQT QlineEdit signal problem



mist
13th June 2018, 19:05
Hi!
Please, someone help me! :)

I have a QLineEdit and I want to assign a Signal (textChanged()) to do something (to lock a Table Widget) when the lineEdit is no blank.

i assigned the control textChanged() to a function which lock the table with: ui.tbPf.setEnabled(False) but when type some characters to this lineEdit, the table is not locked?

What I do wrong? I have to use other Signal?


Thank's a lot!

Ginsengelf
14th June 2018, 07:13
Reported the spam in #2.

On the topic:
- do you get any messages after you started your program the say something like "is no slot" or "is no signal"?
- could you post some actual code?

Ginsengelf

mist
14th June 2018, 09:00
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)

QtCore.QObject.connect(
ui.txProces, QtCore.SIGNAL('keyPressEvent()'), lkTables)
MainWindow.show()
sys.exit(app.exec_())

def lkTables():
ui.tbPf.setEnabled(False)
ui.tbEl.setEnabled(False)

No errors, no nothing

Ginsengelf
14th June 2018, 13:47
QtCore.QObject.connect(ui.txProces, QtCore.SIGNAL('keyPressEvent()'), lkTables)

I don't use PyQt, but this looks wrong to me: no receiver slot defined, and in C++ keyPressEvent is an event, not a signal, so it cannot be used like this.
In C++ you would overload the keyPressEvent() method to add some custom stuff.

Ginsengelf

mist
14th June 2018, 15:50
I don't use PyQt, but this looks wrong to me: no receiver slot defined, and in C++ keyPressEvent is an event, not a signal, so it cannot be used like this.
In C++ you would overload the keyPressEvent() method to add some custom stuff.

Ginsengelf

What is the easiest way to check if the text in a qlineedit is not blank?

d_stranz
15th June 2018, 20:03
QLineEdit::text() to get the text into a QString, QString::isEmpty() to check if it is blank. Connect your slot to the QLineEdit::editingFinished() signal to get notified when the user has stopped editing in the line edit.

I am sure that there must be some PyQt examples that cover such basic operations as retrieving text from a line edit.