How to add a scrollbar to parent QWidget

user408307 picture user408307 · Aug 2, 2010 · Viewed 8.7k times · Source

I understand how to add a scrollArea to a particular widget. However in my case Qwidget has multiple child widgets and these are all set using QVBoxLayout. Now how can I add a scroll bar in this case? Here QWidget is not the center widget, its one of the pages of the TabWidget. My code looks like:

QTabWIdget *center = new QTabWidget; setCentralWIdget(center);

xTab = new QWidget;

formLayout = new QFormLayout; formLayout->addWidget(...); formLayout->addWidget(...); formLayout->addWidget(...); formLayout->addWidget(...);

xTab->setLayout(formLayout);

Now how can I set the scrollBar to xTab? I tried using

scrollArea = new QScrollArea;
scrollArea->setWidget(xTab);

however, this isn't working.

Any idea/suggestions are helpful and appreciated.

Answer

ak. picture ak. · Aug 4, 2010

Have you tried using QScrollArea as the tab page?

QTabWIdget *center = new QTabWidget; setCentralWIdget(center);

xTab = new QScrollArea; 
formLayout = new QFormLayout; formLay....
xTab->setLayout(formLayout);
center->addTab(xTab, "XXX Tab");