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.