How to know QTextEdit'height, when widget is hidden?
-
Hi,
I have QWidget. I have to set on it many QTextEdits with textes, which I don't know ( they are from database ). I setFixedWidth in this QTextEdits to 200. I don't know their height. If text will be short, QTextEdits' height will be small etc. I need to know their height.
There is very good method for me from QTextDocument. I do:
document()->size();
but this function works only when QTextEdits are visible! It works when QTextEdits are hidden but get me height = 0.
I want other method to this the same, but when QTextEdits are hidden and get me real height ( not 0 ). -
@qwe3 if height to be adjusted automatically when it's visible, then set the vertical size policy: Expanding and set the line wrap mode
https://doc.qt.io/qt-5/qtextedit.html#lineWrapMode-prop
Can you explain the usecase of your requirement. Is there any reason to get the size when it's hidden? -
@qwe3 said in How to know QTextEdit'height, when widget is hidden?:
But maybe there is a way to calculate this before "show()"?
I know that problem very well. So far, we have not found a solution to this than to show the widget first. Somehow the sizes of widgets inside a layout are not calculated before the widget is shown for the first time. There are two functions that are supposed to recalculate the layout (
QLayout::update()
andQWidget::adjustSize()
), but they don't do anything in this context.