Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get Linecount of QPlainTextEdit
Forum Updated to NodeBB v4.3 + New Features

Get Linecount of QPlainTextEdit

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • KampiK Offline
    KampiK Offline
    Kampi
    wrote on last edited by
    #1

    Hello,

    I use a QPlainTextEdit as a console window.
    Not I want to get the number of the last line. I use this method actually:

    int Console::getLines( void )
    {
        return this->toPlainText().split( "\n" ).size();
    }
    

    This methode doesn´t wort well, because it returns a wrong value when a line is wrapped, because the wrapped line doesn´t contain a carriage return.
    Does anybody knows a better solution to count the lines? I doesn´t want any solution which works with the current cursor position, because I want to move the cursor in the console window.

    Thank you for help

    raven-worxR 1 Reply Last reply
    0
    • KampiK Kampi

      Hello,

      I use a QPlainTextEdit as a console window.
      Not I want to get the number of the last line. I use this method actually:

      int Console::getLines( void )
      {
          return this->toPlainText().split( "\n" ).size();
      }
      

      This methode doesn´t wort well, because it returns a wrong value when a line is wrapped, because the wrapped line doesn´t contain a carriage return.
      Does anybody knows a better solution to count the lines? I doesn´t want any solution which works with the current cursor position, because I want to move the cursor in the console window.

      Thank you for help

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Kampi
      QTextDocument::blockCount()

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • KampiK Offline
        KampiK Offline
        Kampi
        wrote on last edited by
        #3

        Hello raven,

        thank you for this hint, but this doesn´t solve my problem, but I found the linecount property in the description of blockCount. I´ve solved my problem with this. Thank you anyway.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved