trouble with height-for-width
-
Hi,
I'm playing with flowlayout-example and added some dialog-like widgets of constant size.
This is a screenshot of all children in a big-enuf container:
... but I don't have that plenty space in my app, so real app-window looks like this:
Layout works as expected, but elements outside of visible container can't be accessed.So I added a QScrollArea, which leads to this picture:
Now layout does not calculate any other possible width, as the smallest width could be made high enuf for all children.I don't want to limit height of scrollarea - number of children and (constant) size is variable. So I'm looking for a way to change layout so that first the width is occupied, before wrapping happens.
I guess to achieve that, I have to overload some internal Qt classes. If anybody has done something similar, a helping hand is appreciated!
-
Hi,
Are you applying the layout on the QScrollArea itself or on a widget that you set on the QScrollArea ?
-
Hi,
I was puzzled by your question. I was about to write "of course I assigned the layout to the widget that was included in the scrollarea ...", but then I thought: Hey, why not ...
... and tried it out: Unfortunately, after adding the layout, the ScrollArea was no longer a ScrollArea. At least there were no scrollbars and the ContentArea was also fixed.Now I don't know what to do. Should I assign the layout to the ScrollArea and research why there are no scrollbars anymore, or was the first way more correct?
In between I thought maybe I could use the resize event to make the layout recalculate from the top, but after a resize event so much goes off internally that I have no plan what I need from it, or how to get my layout to act only on my request.
-
@django-Reinhard
@SGaist was just verifying that you did indeed assign layout to widget, not to scroll area. This is correct way. -
Hi,
just to close this:
I compiled a Qt with debug info and debugged the layout process. Then I thought, I should extend
QLayout::totalSizeHint()
- but that function is not virtual. So patching Qt would become expensive :(So I thought, may be
QScrollArea
has a property for preferred extend direction - which is not the case.
But on that research I discoveredQScrollArea::setWidgetResizable()
...Oh happy day! That did the trick :)
I have nothing to extend or patch, just use this property.
What a revelation :DFinally my code looks something like this:
Window::Window() : client(new QWidget(this)) { FlowLayout* fl = new FlowLayout; QScrollArea* sa = new QScrollArea; setLayout(new QVBoxLayout); layout()->setMargin(0); client->setLayout(fl); fl->setMargin(0); fl->addWidget(...); fl->addWidget(...); ... sa->setWidget(client); sa->setWidgetResizable(true); layout()->addWidget(sa); }
... and the result looks like:
Yeah!