PDA

View Full Version : QTextDocument update size



Grzyboo
8th September 2015, 16:33
How to update the size of QTextEdit's document?

i have such function:


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:


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?

ChrisW67
11th September 2015, 22:59
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.