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. count chars in line QTextEdit

count chars in line QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 449 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.
  • M Offline
    M Offline
    Martinuccia_96
    wrote on 18 Apr 2020, 07:59 last edited by
    #1

    Hi, everyone.
    Let's considering a qTextEditBlock.
    By using the QTextCursor, is there any way to count the number of chars present in a line?
    I move on the line where I want to count the chars in the following way:

    QTextCursor curs=ui->textEdit->textCursor();
    curs.movePosition(QTextCursor::Start);
    curs.movePosition(QTextCursor::NextBlock,QTextCursor::MoveAnchor, line)
    

    where line is an integer that indicates the block in which I want to move.
    Now, how can I do?
    Thanks to everyone

    R 1 Reply Last reply 18 Apr 2020, 09:10
    0
    • M Martinuccia_96
      18 Apr 2020, 07:59

      Hi, everyone.
      Let's considering a qTextEditBlock.
      By using the QTextCursor, is there any way to count the number of chars present in a line?
      I move on the line where I want to count the chars in the following way:

      QTextCursor curs=ui->textEdit->textCursor();
      curs.movePosition(QTextCursor::Start);
      curs.movePosition(QTextCursor::NextBlock,QTextCursor::MoveAnchor, line)
      

      where line is an integer that indicates the block in which I want to move.
      Now, how can I do?
      Thanks to everyone

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 18 Apr 2020, 09:10 last edited by raven-worx
      #2

      @Martinuccia_96

      curs.block().length()
      

      --- 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
      2
      • M Offline
        M Offline
        Martinuccia_96
        wrote on 18 Apr 2020, 12:03 last edited by
        #3

        but what if the number of chars is lower than the block length? For example if I push the enter button on the keyboard..

        R 1 Reply Last reply 18 Apr 2020, 15:07
        0
        • M Martinuccia_96
          18 Apr 2020, 12:03

          but what if the number of chars is lower than the block length? For example if I push the enter button on the keyboard..

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 18 Apr 2020, 15:07 last edited by
          #4

          @Martinuccia_96
          then its a new block

          --- 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
          2

          2/4

          18 Apr 2020, 09:10

          • Login

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