Results 1 to 11 of 11

Thread: how can I find number of lines in QTextedit ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Wink Re: how can I find number of lines in QTextedit ?

    Hi, Jpn nearly give you the answer, I suggest you to find a tutorial on how using the Qt4 Assistant.

    I'm in a good moon, I will explain you.

    Qt Code:
    1. QTextDocument * QTextEdit::document () const
    To copy to clipboard, switch view to plain text mode 

    As you can see, this method return a QTextDocument* and as jpn said in his first reply, this class have the property you are looking for :
    Qt Code:
    1. blockCount : const int
    To copy to clipboard, switch view to plain text mode 

    Finishing with a little example (very little) :
    Qt Code:
    1. ...
    2. QTextEdit *textEdit;
    3. int i = textEdit->document()->blockCount();
    4. ...
    To copy to clipboard, switch view to plain text mode 
    and i will contain the number of lines that textEdit contain. (more exactly the number of return, I mean an empty line is also counted)

    Hope this will be enough ^^ and hope you will give more importance to the doc !!

    Cheers.

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

    Default Re: how can I find number of lines in QTextedit ?

    Quote Originally Posted by redkite View Post
    and i will contain the number of lines that textEdit contain. (more exactly the number of return, I mean an empty line is also counted)
    I think these are called paragraphs Of course excluding empty blocks unless you treat them as empty paragraphs...

  3. The following user says thank you to wysota for this useful post:

    WarGamer (4th October 2012)

Similar Threads

  1. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  2. How to retrieve lines from QTextEdit -- easy way?
    By macias in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 15:44
  3. QTextEdit: how to get lines?
    By claudio in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2007, 21:08
  4. Line Number - QTextEdit...???
    By deepusrp in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 16:34
  5. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13

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
  •  
Qt is a trademark of The Qt Company.