PDA

View Full Version : How to clear the GridLayout



rahulgogoi
11th May 2011, 07:16
hello friends

Actually i have an GridLayout where i add array of buttons in the layout..now on next call when i again tried to add array of buttons in that layout than some of the buttons that are previously added are also display in the layout...so how is it possible to clear the layout on each call..if so how it can be done..please suggest me..

regards
rahul

wysota
11th May 2011, 14:25
Delete the widgets that are in the layout before adding new ones.

rahulgogoi
12th May 2011, 09:00
yeh i had write the code like that but its not working..


for(int i=0;i<6;i++)
{
for(int j=0;j<7;j++)
{

controlsLayout->removeWidget(cellBut[i][j]);
}
}

wysota
12th May 2011, 09:09
What do you consider "not working"? removeWidget() doesn't delete the widget so it stays on the form right where it was, only that it is not managed by a layout anymore.

rahulgogoi
12th May 2011, 09:22
Actually it remove buttons at last row..but doesnt remove buttons at first row..

wysota
12th May 2011, 09:27
Try calling "delete" on the widget instead.

rahulgogoi
13th May 2011, 07:01
hello wysota

how can i interact with each buttons that i have used in creating my custom
calender means i want to say suppose i click one button than it will give
all the information of that buttons ie in which month,which week ie
sun,mon,tue..etc is shown in textBrowser.

i have tried to done one thing..


for(int i=0;i<6;i++)
{
for(int j=0;j<7;j++)
{
cellBut[i][j]=new QPushButton;
connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(showDialog()));
}
}
void MainWindow::showDialog()
{
txtDateDisplay->setText("Hello");
}

now here on each button click i simply set a text hello in the txtDateDisplay..now if i want that on each button click i set the text that appear on button in txtDateDisplay than how should i do it..because here i cant pass arguments in SIGNAL(Clicked()) function..

regards
Rahul

Lykurg
13th May 2011, 07:22
See QSignalMapper.