QTextDocument update size
How to update the size of QTextEdit's document?
i have such function:
Code:
void QTextEditExtended::setHeightByDoc()
{
int iHeight = this->document()->size().height();
this->setMinimumHeight(iHeight);
this->setMaximumHeight(iHeight);
}
It's supposed to adjust widget size to text size.
It works fine on signal textChanged, but doesn't work after inserting text by code (height is always 21).
Simple example:
Code:
pText->insertPlainText("blablablabla\r\n");
pText->insertPlainText("blablablabla\r\n");
pText->insertPlainText("blablablabla\r\n");
pText->insertPlainText("blablablabla");
pText->setHeightByDoc();
The height of pText widget will be 21. However, if i activate textChanged signal by e.g. adding a space into my TextEdit, everything works fine and height is set properly. So, my question is how to update document's size after inserting text by code?
Re: QTextDocument update size
Adjust your widget every time the document signals you its contentChanged().
Also ask yourself what happens when the document height is greater than the screen height. The text edit has scroll bars for a reason.