Results 1 to 3 of 3

Thread: Update label to display a text field's character count?

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Update label to display a text field's character count?

    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:
    Qt Code:
    1. On keypress()
    2. lblCharacters.caption = len(txtTyping.text)
    To copy to clipboard, switch view to plain text mode 

    Can someone help me with the equivalent in Qt?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Update label to display a text field's character count?

    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().

  3. #3
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update label to display a text field's character count?

    Thank you, I'll try that. I see I still have a lot to learn.

Similar Threads

  1. How to display individual character of a string?
    By cooper in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2009, 05:19
  2. How to get text field content in QWebView
    By richardander in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 07:04
  3. Need to make QLCDNumber display count up/down
    By JimDaniel in forum Newbie
    Replies: 2
    Last Post: 29th September 2007, 01:59
  4. Determine if a font can display a character
    By jrideout in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2006, 10:33
  5. count line number in text
    By Alina in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2006, 08:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.