adding items in scroll area dynamically
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
Re: adding items in scroll area dynamically
how are you adding your items? can we see the code?
Re: adding items in scroll area dynamically
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.
Re: adding items in scroll area dynamically
Hi,
Thanks for the reply. Pls find the code below for your reference.
This is the code for my scroll area in my mainwindow..
Code:
scrollArea
->setObjectName
(QString::fromUtf8("scrollArea"));
scrollArea
->setGeometry
(QRect(1050,
168,
208,
684));
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..
Re: adding items in scroll area dynamically
pls edit your post and add [ CODE ] tags :]
Re: adding items in scroll area dynamically
ok, and I see you have to use layouts :]
Just add the QVBoxLayout to your scroll area and place widgets in it.