PDA

View Full Version : Fixed height of Qt Vertical Box Layout. Anything else than putting it in new QWidget.



Divad
17th January 2014, 18:04
Hey all!

I have a scroll area.
What I want is to dynamically create and add QTextEdit (with different text) in this scroll area. And depending on some variables, current QTextEdit will placed on the left or right hand side.
Think about facebook conversation : incoming messages will be on the left, and outgoing ones will be on the right.

To add QTextEdit to this area, I use QVBoxLayout : I begin to add new QVBoxLayout and in that layout I add my QTextEdit. And again and again, new QVBoxLayout below the older ones. After that, I apply Qt:Alignement to each of these layouts.
Why I add QVBoxLayout first ? Because It actually lets users to resize the window of the application while keeping the QTextEdit entirely visible in the area.

My problem is when I add these layouts, they all are visible in the area, that means their sizes are reduced.
I want them to have maximum height. Users will use the scrollbar of the scroll area to see other QTextEdit.

Can someone help me ? Thank you ..

sulliwk06
17th January 2014, 21:08
Is the scroll area the whole application, or is there more outside the scroll area?

So you want it to where when the scroll area is resized, the text edits are completely visible from a horizontal perspective, but from a vertical perspective some text edits are outside the view of the scroll area? Is that correct?

ChrisW67
18th January 2014, 03:42
There is no "maximum height" for a QTextEdit. A QTextEdit will grow as tall (or short) as you let it.

A vertical layout will size the text areas into the space available in the widget the layout is applied to: in this case the container widget inside the scroll area view port. If you don't increase its size when you add new material then existing material shrinks to accommodate it. You can have the container widget automatically adopt the size of the accumulated sizeHint()s of child widgets using a Fixed vertical size policy. See the "Extension Example" in Assistant.