Results 1 to 5 of 5

Thread: QPlainText Edit and text lines

  1. #1
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QPlainText Edit and text lines

    Hello:

    I was wondering if there is any way to make the cursor go to specific line number of a text written in QPlainTextEdit.

    Thank you for any answers.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPlainText Edit and text lines

    pQPlainTextEdit->textCursor->setPos().

    A line number can be deduced from the number of new lines ('\n')
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPlainText Edit and text lines

    Linenumber: as in with our without taking the line wrapping into account?

    Without:

    Qt Code:
    1. int pos = plaintextedit->document()->findBlockByNumber(yourparagraphnumber).position();
    To copy to clipboard, switch view to plain text mode 

    To set the cursor there:
    Qt Code:
    1. QTextCursor cur = plaintextedit->textCursor();
    2. cur.setPosition(pos);
    3. plaintextedit->setTextCursor(cur);
    To copy to clipboard, switch view to plain text mode 

    Johannes

  4. #4
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPlainText Edit and text lines

    Yes that was exactly what I wanted!

    Thank you.

    The thing is that I had found the findBlockbyNumber (or LineNumber, too) but I had not found the .position() property of the block to turn it into an integer with which to set the textCursor.

    Thank you again!

  5. #5
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPlainText Edit and text lines

    You are welcome! No need to say thanks twice, though :-> Just use the forums thank button!

    Happy coding!

    Johannes

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  2. Character encoding in text edit and llne edit
    By greenvirag in forum Qt Programming
    Replies: 3
    Last Post: 20th January 2009, 08:45
  3. Qt class showing text area/text edit
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 21st August 2008, 12:15
  4. I want to get lines of text
    By newplayer in forum Qt Programming
    Replies: 11
    Last Post: 29th July 2008, 09:03
  5. Replies: 8
    Last Post: 15th May 2007, 09:21

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.