PDA

View Full Version : multiple textedits inside layouts and scrollarea



andres
24th October 2010, 22:18
Hi,

not sure if this is trivial, but I cannot seem to find the solution for this one... so maybe a kind soul can steer me towards the solution?

I'm trying to have two QTextEdit widgets managed by a QVBoxLayout inside a QScrollArea in such a way that: QTextEdits never (need to) show their scrollbars but that instead the scroll area grows. The QTextEdits also should only use the minimum amount of vertical space.

Whatever I do, the QTextEdits will always eventually show scrollbars...

Do I have to write my own layout manager?

Cheers,

Andres

wysota
24th October 2010, 23:36
Reimplement sizeHint() from QTextEdit to take into consideration QTextDocument::size of the document it is showing and set the size policy of the text edit widget to minimumExpanding or similar.

Here is a sample implementation (you might just copy it): http://doc.qt.nokia.com/qt-maemo-4.6/maemo5-textedit-texteditautoresizer-h.html

andres
26th October 2010, 18:47
Reimplement sizeHint() from QTextEdit to take into consideration QTextDocument::size of the document it is showing and set the size policy of the text edit widget to minimumExpanding or similar.

Here is a sample implementation (you might just copy it): http://doc.qt.nokia.com/qt-maemo-4.6/maemo5-textedit-texteditautoresizer-h.html

this is good stuff, it still doesnt quite work though.. the QTextEdit still creates the scrollbar. Have checked with debugger that the TextEditAutoResizer::textEditChanged() method gets called and it does indeed adjust the minimumHeight of the QTextEdit widget. What I dont understand is why the QScrollArea that contains the QVBoxLayout is not trying to grow... weird.

Thanks anyways.

wysota
26th October 2010, 18:55
Set the "widgetResizable" property of the scroll area to true.