I use a QTextEdit for some inputs. But I want to adjust the height of the box. Can I set the height based on the number of lines I want to have visible at a time?
相关问题
- Sorting 3 numbers without branching [closed]
- QML: Cannot read property 'xxx' of undefin
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
相关文章
- ubuntu20.4中c#通过c++库调用python脚本
- Qt槽函数自动执行多遍
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
This should work:
If you use
QPlainTextEdit
, something like this should do the trick:You might want to add two or three pixels as margin; experiment will tell.
Use
QFont
to determine the height of a single line of text in theQTextEdit
(QTextEdit should have a font property). After that multiply theQFont
's height value with the number of lines you want to show and set the widget's (minimum-)height to that value.Improving the accepted answer about
QPlainTextEdit
. In addition tolineSpacing
, value forsetFixedHeight
should contain: 2 margins of the underlyingQTextDocument
, 2 widths of the frame and widget's contents margins. Besides that,QFontMetrics
must be got from a font of the document, not of the widget itself. So, hypothetical functionsetHeight
should read as follows:QTextEdit is a normal widget, so you can use minimumHeight property. I believe, however, that it is really impossible to set minimum height based on number of lines. This would resize automagically the minimum size of a widget every time you change size of the font. But if you know the size of the font, you can set some usable minimum size of your widget.