There is a fixed-width QTextEdit . It is necessary that when it is filled with text, it expands upwards, but the scroll bar simply turns on. Many googlin, but did not find anything that helped.
Wrote such a crutch

 connect(text_input, &CSTextEdit::textChanged, [this]() { int height = QFontMetrics(text_input->font()) .boundingRect(QRect(), text_input->alignment(), text_input->toPlainText()) .height(); height = height > 47 ? height : 47; text_input->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); text_input->setMaximumHeight(height); }); 

But it turned out that the line break is only visual and all this text is one line, therefore the height remains unchanged.

  • And what prevents to write your textedit, with such behavior as you need? - awesome
  • @awesome so I ask how to do it adequately - sm4ll_3gg
  • Inherit from QTextEdit and override the methods you need. - awesome
  • @awesome, can you have more specifics? I know how to do it, but I don’t know what methods need to be overridden in order for it to work normally without crutches - sm4ll_3gg

0