1

I've created a QTextEdit which initializes empty, after that the following code executes (TE being a pointer to the textedit):

    TE->setText( "this is a test string, it should have a non zero height");
    auto d(TE->document());
    auto s(d->toPlainText());
    auto _s(d->size());
    auto _h(_s.height());

Through debugging I see that the string s is set correctly. However the size _s simply is 0. Why, and how to fix. Shouldn't this snipped work everywhere and in any place? I've also tried adding a TE->show() line in case the resizing only happens when showing the widget, but to no avail. What is causing this?

genpfault
  • 51,148
  • 11
  • 85
  • 139
paul23
  • 8,799
  • 12
  • 66
  • 149

1 Answers1

0

Changing the text in the document does not change the document width. From the docs for QTextDocument.

The size of the document can be changed either by setting a text width or setting an entire page size.

Perhaps calling d->adjustSize() will get you where you want to be? However, note that changing the size of the document won't change the size of the QTextEdit widget.

kenrogers
  • 1,350
  • 6
  • 17
  • Well that's just weird, as somebody just told it does. http://stackoverflow.com/questions/9506586/qtextedit-resize-to-fit In that question I asked the problem the other way round. I just want a way to get the actual size of the text in a widget (given the widget's width & wordwrapping). – paul23 Mar 01 '12 at 21:54