PDA

View Full Version : Update label to display a text field's character count?



Eskimo
7th April 2010, 17:10
Hello folks. I'm new to this forum but I have already learned quite a bit.
First, thanks for such a great resource.

A quick search of the forum did not turn up an answer to this (I assume) easy question.

I have a form that has a text field and a label. I am trying to update the label's text property with the character count in the text field.

A pseudo-VB code may be something like:

On keypress()
lblCharacters.caption = len(txtTyping.text)

Can someone help me with the equivalent in Qt?

wysota
7th April 2010, 20:05
Connect the textChanged() signal from QLineEdit (or an appropriate equivalent from QTextEdit) to a custom slot where you will read the text from the text widget (textChanged() signal carries it as a parameter), check its size using QString::size(), convert it from integer to string using QString::number() and set it on the label using QLabel::setText().

Eskimo
8th April 2010, 16:16
Thank you, I'll try that. I see I still have a lot to learn.