I have created my own widget that I'm going to put into another widget from code. The form widget are created with qtCreator. I have arranged the "subwidgets" into a verticalLayout in order to put one under the other, but since the number of the inserted widget is not fixed I need to have a scrollbar. So I have placed my verticalLayout into a scrollArea, but the scrollbar never appears, why? the structure "father->child" is the following: formWidget->scrollArea->verticalLayout Thanks
EDIT: The problem is the following: I was creating the widget from a the clicked slot of a QPushButton: in the costructor of that widget, I was creating a QScrollArea and a VerticalLayout. After having been inserted all the widgets that I want in the layout, I added the layout to the scrollArea. This is the wrong thing: in order to make visible the scrollArea in the widget created from the button, is necessary to inserted that widget in the scrollbar, directly from the clicked slot code. For further detail, I attach the code of the clicked slot and the widget constructor
Button slot (clicked)
scrollArea= new QScrollArea;
scheduleWindow = new Schedule(traceFilePath);
scrollArea->setWidget(scheduleWindow);
scrollArea->resize(scheduleWindow->getWidth(), scheduleWindow->getHeight());
QRect rec = QApplication::desktop()->screenGeometry();
unsigned int desktopHeight = rec.height();
unsigned int desktopWidth = rec.width();
if(scheduleWindow->getWidth() > desktopWidth ||
scheduleWindow->getHeight() > desktopHeight)
scrollArea->showMaximized();
else
scrollArea->show();
Widget constructor
Schedule::Schedule(QString pathname, QWidget *parent) :
QWidget(parent),
ui(new Ui::Schedule)
{
ui->setupUi(this);
traceParser parser(pathname);
parser.readJson();
ArchitectureParameter arch = parser.getArchParam();
QString taskName;
unsigned int nTasks = 0;
TaskSchedule *t;
for(std::list<QString>::iterator taskNameIter = parser.getTaskNames().begin();
taskNameIter != parser.getTaskNames().end(); taskNameIter++)
{
taskName = *taskNameIter;
nTasks++;
cout<<taskName.toStdString()<<endl;
t = new TaskSchedule(this , taskName, 80, arch.nCPU(), arch.maxTime(),
parser.getExecList(taskName), parser.getTaskSimpleEventsMap(taskName));
ui->pageLayout->addWidget(t);
}
cout<<nTasks<<endl;
width = 2*t->getLineXPosStart() + t->getTickLength()*arch.maxTime();
height = nTasks*(2*TASKSCH_Y_OFFSET + arch.nCPU()*t->getCpuHeight());
ui->area->resize(width, height);
ui->area->setMinimumSize(width, height);
this->adjustSize();
}