PDA

View Full Version : adding items in scroll area dynamically



Ezhil
20th May 2009, 11:54
hi,

I am adding a groupbox to the scroll area dynamically whenever new connection is made i.e whenever Connection button is clicked, it will create a new connection and a groupbox will be
created with connection name and is placed on the scroll area.

My problem the scroll area can display only 10 such group boxes,when my connection exceeds 10, i am unable to view my new connection.

I wud like to know how to enable the scrollbar when my contents exceeds the scroll area widget size, to view all the item added to scroll area.

I use QT designer to design my mainwindow and groupbox is created using code(whenever connection clicked event is generated)

Note:I use verticalscrollbarPolicy as scrollBarAlwaysOn, but still it is not working.

Pls anyone help me solve this problem.

Thanks,
Ezhil

faldzip
20th May 2009, 12:34
how are you adding your items? can we see the code?

Lykurg
20th May 2009, 12:57
I guess a lecture of "Size Hints and Layouts" at the QScrollArea docs will provide the solution to you, if not we need some more code - as said.

Ezhil
22nd May 2009, 13:57
Hi,

Thanks for the reply. Pls find the code below for your reference.


This is the code for my scroll area in my mainwindow..


scrollArea = new QScrollArea(centralwidget);
scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
scrollArea->setGeometry(QRect(1050, 168, 208, 684));
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
scrollArea->setSizePolicy(sizePolicy);
scrollArea->setStyleSheet(QString::fromUtf8("background-color: rgb(255, 255, 255);"));
scrollArea->setFrameShadow(QFrame::Sunken);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setWidgetResizable(true);
scrollArea->setAlignment(Qt::AlignJustify|Qt::AlignTop);
scrollAreaWidgetContents = new QWidget();
scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
scrollAreaWidgetContents->setGeometry(QRect(0, 0, 206, 682));

Code for placing groupbox in scrollarea..

void mainwindow::creatDatabaseBox()
{
static int cCnt = 0;
static int yAxis = 30;
++cCnt;

databaseGrpBox = new QGroupBox(ui.scrollAreaWidgetContents);
databaseGrpBox->setObjectName(QString("dataBaseGrpBox%1").arg(cCnt));
databaseGrpBox->setGeometry(QRect(10,yAxis,174,50));
databaseGrpBox->setTitle("QString("dataBaseGrpBox%1").arg(cCnt)");

yAxis = YAxis+55;
}

This will be called when a connection button is pressed..

faldzip
22nd May 2009, 16:29
pls edit your post and add [ CODE ] tags :]

faldzip
22nd May 2009, 16:33
ok, and I see you have to use layouts :]
Just add the QVBoxLayout to your scroll area and place widgets in it.