How do I react on the resize of a QMainWindow
? I have QTextBrowsers
in a QScrollArea
and I adjust them to the size of the content on creating them (the only thing that should scroll is the QScrollArea
).
Everything works for now, but if I resize the mainWindow
, the height of the QTextBrowsers
isn't changed, because the reflow function isn't triggered.
Do you have any better idea to adjust a QTextBrowser
to it's content? My current code is:
void RenderFrame::adjustTextBrowser(QTextBrowser* e) const {
e->document()->setTextWidth(e->parentWidget()->width());
e->setMinimumHeight(e->document()->size().toSize().height());
e->setMaximumHeight(e->minimumHeight());
}
The parentWidget()
is necessary because running width()
on the widget itself returns always 100, regardless of the real size.
If there is only text or html, you could use
QLabel
instead, because it already adapts its size to the available space. You'll have to use:to have almost the same behavior as a
QTextBrowser
.If you really want to use a
QTextBrowser
, you can try something like this (adapted fromQLabel
source code):