[Qt-interest] How to put a QLayout in a QScrollArea ?

Sean Harmer sean.harmer at maps-technology.com
Mon Dec 14 18:13:50 CET 2009


Hi,

On Monday 14 December 2009 16:52:33 Stephen Collyer wrote:
> I want to create a scrollable widget containing a QVBoxLayout of other
> widgets. However, QScrollArea::setWidget() wants a QWidget*, not a
>  QLayout*.
> 
> Is there straightforward way to do this ?

Yes, add your QVBoxLayout to a QWidget and then add this QWidget to the 
QScrollArea using setWidget(). For e.g.

QVBoxLayout* layout = new QVBoxLayout;
// Add widgets to layout...

QWidget* w = new QWidget;
w->setLayout( layout );

myScrollArea->setWidget( w );

HTH,

Sean



More information about the Qt-interest-old mailing list