I have tried everything but can't seem to get scrollbars to appear when using flowlayout. As an easy test case, I'm trying to modify the flowlayout demo to show scrollbars when you resize the window smaller than content area.
I saw in the scrollarea doc
If a scroll area is used to display the contents of a widget that contains child widgets arranged in a layout, it is important to realize that the size policy of the layout will also determine the size of the widget. This is especially useful to know if you intend to dynamically change the contents of the layout. In such cases, setting the layout's size constraint property to one which provides constraints on the minimum and/or maximum size of the layout (e.g., QLayout::SetMinAndMaxSize) will cause the size of the scroll area to be updated whenever the contents of the layout changes.
I commented out the old layout linking directly to the parent window, and added code to put up scrollbars. Can anybody see anything wrong with this code?
EDIT: Forgot to say the problem - The window won't resize smaller than all the controls.
Window::Window()
{
FlowLayout *flowLayout = new FlowLayout;
flowLayout
->addWidget
(new QPushButton(tr
("Different text")));
flowLayout
->addWidget
(new QPushButton(tr
("More text")));
flowLayout
->addWidget
(new QPushButton(tr
("Even longer button text")));
// setLayout(flowLayout);
scrollWidget->setLayout(flowLayout);
scrollArea->setWidget(scrollWidget);
flowLayout
->setSizeConstraint
(QLayout::SetMinAndMaxSize);
centralLayout->addWidget(scrollWidget);
this->setLayout(centralLayout);
setWindowTitle(tr("Flow Layout"));
}
Window::Window()
{
FlowLayout *flowLayout = new FlowLayout;
flowLayout->addWidget(new QPushButton(tr("Short")));
flowLayout->addWidget(new QPushButton(tr("Longer")));
flowLayout->addWidget(new QPushButton(tr("Different text")));
flowLayout->addWidget(new QPushButton(tr("More text")));
flowLayout->addWidget(new QPushButton(tr("Even longer button text")));
// setLayout(flowLayout);
QWidget *scrollWidget = new QWidget();
scrollWidget->setLayout(flowLayout);
QScrollArea *scrollArea = new QScrollArea();
scrollArea->setWidget(scrollWidget);
flowLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
QHBoxLayout *centralLayout = new QHBoxLayout();
centralLayout->addWidget(scrollWidget);
this->setLayout(centralLayout);
setWindowTitle(tr("Flow Layout"));
}
To copy to clipboard, switch view to plain text mode
Bookmarks