Search code examples
c++qtqplaintextedit

QPlainTextEdit - absolute size


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.


Solution

  • You can do it like this in your derived class:

    int TextEditor::contentHeight() const
    {
        return contentOffset().y() + fontMetrics().lineSpacing() * blockCount();
    }