PDA

View Full Version : scrollArea



skizzik
12th January 2011, 08:17
I have created a scrollArea in the designer in Qt Creator. Its scrollAreaWidgetContents have a grid-layout. If I put in an object in the area in the designer, the scrollbar works fine. But if I create an object later in the code, the scrollbar doesn't work and the object is simply cut if the window is too small. What to do?

To create an object in the scrollArea, I simply write:


QGroupBox *b = new QGroupBox(mainWindow->scrollArea);
b->resize(100,600);

The box show up in the scrollArea, in the top left corner.

Thanks!

franz
12th January 2011, 12:55
It's probably better to explicitly add your new widget to the scroll area:


QGroupBox *b = new QGroupBox;
b->resize(100,600);
mainWindow->scrollArea->setWidget(b);


It is probably bad style (read about encapsulation) to have member variables publicly (or even protected) available. Also, please use code tags on the forum when posting code.