Unsolved How do I keep a QTextEdit widget from scrolling?
-
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:
And have the input restricted to two lines that are the lines that fit on this size with this font size, like this:
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!
-
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 ?
-
@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.
-
@m4l490n
Hi
Why not simply use 2 LineEdits then ?
You can set text maxLength on both and it will give a similar effect.