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. How do I keep a QTextEdit widget from scrolling?

How do I keep a QTextEdit widget from scrolling?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 534 Views 2 Watching
  • 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.
  • m4l490nM Offline
    m4l490nM Offline
    m4l490n
    wrote on last edited by
    #1

    I need to place a text edit box of a certain size and I need to constrain the input to just the text that can be fit without scrolling. How do I achieve this?

    I want to prevent this:

    0_1557791269575_0383512d-40e9-4bc8-9f53-f04fec15884e-image.png

    And have the input restricted to two lines that are the lines that fit on this size with this font size, like this:

    0_1557791395169_a0ed8038-0000-431b-af1b-a7fadb18262e-image.png

    So if the user keeps entering text, the box won't allow anything past the last character that fits on the second row

    Any ideas?

    Thanks!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Subclass QTextEdit and override keyPressed event.
      There use QFontMetrics fm(this->font);
      to check size of the text. if too big, ignore key
      else add key to the text.

      I assume you want 3 lines if font is smaller so its not always 2 lines ?

      m4l490nM 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        Subclass QTextEdit and override keyPressed event.
        There use QFontMetrics fm(this->font);
        to check size of the text. if too big, ignore key
        else add key to the text.

        I assume you want 3 lines if font is smaller so its not always 2 lines ?

        m4l490nM Offline
        m4l490nM Offline
        m4l490n
        wrote on last edited by
        #3

        @mrjj said in How do I keep a QTextEdit widget from scrolling?:

        I assume you want 3 lines if font is smaller so its not always 2 lines ?

        Hello, thanks for helping!

        No, I always want the same font size and only two lines. So, if the user writes enough to reach the end of the second line, then they can't input more text.

        mrjjM 1 Reply Last reply
        0
        • m4l490nM m4l490n

          @mrjj said in How do I keep a QTextEdit widget from scrolling?:

          I assume you want 3 lines if font is smaller so its not always 2 lines ?

          Hello, thanks for helping!

          No, I always want the same font size and only two lines. So, if the user writes enough to reach the end of the second line, then they can't input more text.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @m4l490n
          Hi
          Why not simply use 2 LineEdits then ?
          You can set text maxLength on both and it will give a similar effect.

          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