Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[5.2.0] QTextEdit sizeHint() always returns the same value/viewport()->layout not set?
Walrus last edited by
I was working with a QTextEdit to display a large block of text (some release notes) recently, and I noticed that it wasn't resizing properly. I had setSizeAdjustPolicy set to AdjustToContents, but it wasn't working. I wound up stepping through the code and discovered that the offender is on qwidget.cpp:7800 in QWidget::sizeHint called from viewportSizeHint.
d->viewport->sizeHint(), is returning(-1,-1) because the viewport's layout is null!
My QTextEdit is in to a Layout, in another layout, in a QDialog, so I figured the layout would be taken care of. Do I have to do something special to setup the viewport? I'm at a loss as to how to fix this.