0

I need to get absolute height of the QPlainTextEdit, as if it's not in QAbstractScrollArea. I've already spent about an hour finding it out. I've searched QPlainTextEdit, QTextDocument and QAbstractScrollArea, tried every property with size in it's name.

I hope there's other way than to multiply the blockCount() by blockBoundingRect(firstVisibleBlock()).height() and add to content offset. (Blocks are the same size.)

Thank you in advance.

LogicStuff
  • 19,397
  • 6
  • 54
  • 74

2 Answers2

0

I think this is what you are looking for: http://qt-project.org/forums/viewreply/21633/

The QScrollArea has a Viewport. The Viewport is the size of the viewable area. So if your QScrollArea is named foo, you'll want to do this:

 foo.viewport().size();

Which will return you your desired QSize.

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • I don't want viewable, I want absolute - out of the bounds of the viewport. – LogicStuff Jan 06 '15 at 21:10
  • @LogicStuff That should be maintained in your original object. So if your `QPlainTextEdit` is named `bar` you should just be able to do: `bar.size();` – Jonathan Mee Jan 06 '15 at 21:16
  • That's the same (plus height of horizontal scroll bar I suppose). – LogicStuff Jan 06 '15 at 21:20
  • @LogicStuff Seems like we're having a miscomunication, Viewport + scroll bars = `QScrollArea.size()`. `bar.size()` is different from the Viewport and the `QScrollArea.size()`... unless you've just gotten really lucky/unlucky with your widget's size. – Jonathan Mee Jan 06 '15 at 21:35
  • I think the OP is asking how to get "how tall would the widget need to be to display all of the content without scrolling vertically" - not the current widget size. – nobody Jan 06 '15 at 21:38
  • Simply, assume `textEdit` has `100` lines of text, but viewport can display only `50`. If height of one line is `15`px, I want to be getting ~`1500`, not `750`. – LogicStuff Jan 06 '15 at 21:45
  • @Andrew Medico Exactly. – LogicStuff Jan 06 '15 at 21:46
0

You can do it like this in your derived class:

int TextEditor::contentHeight() const
{
    return contentOffset().y() + fontMetrics().lineSpacing() * blockCount();
}
LogicStuff
  • 19,397
  • 6
  • 54
  • 74