Setting text for QTextEdit
:
te->setPlainText(“Something”) ;
te->adjustSize();
should wrap around “Something” only, instead the QTextEdit
is expanding to its maximum Width-Height, can’t fix it..
When I select “Something” on run time, only “Something” is highlighted, no added extra white spaces.
Expectations: when text is small enough to fit on one Line, the text edit shouldn’t expand in height, when the text needs to wrap, only the extra line width should be added not the maximum width.
if adjustSize();
is not called, the text will wrap on the width that was set in the .ui in the Creator, won't dynamically expand horizontally nor vertically..
Some Info:
Horizontal Policy: Expanding
Vertical Policy : MinimumExpanding
minimumSize : 2×22
maximum Size : 300×100
lineWrapMode: WidgetWidth
Yes, looks like there is no easy way to count lines in QTextEdit
.adjustSize()
is made for QWidget
and is not reimplemented for QTextEdit
, it is based on sizeHint()
.
You can use your own method to count lines, f.e.
QFontMetrics
to calculate width of every word in your text QTextEdit
itself and subclass it, reimplementing something (adjustSize()
?) there.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With