Creating an Array of Button
hello friends
I am creating an array of buttons having 7 rows 7 colums..
now i trying to display first seven buttons in one row after which it goes to second row and display next seven button..and so on..
i have wrriten a code for this..its working but problem is that all the buttons are displayed in one row only..so if anyone suggest me to resolve that problem..
i am sending my code along with this..
Code:
selectedDate
=QDate::currentDate();
int count=1,i,j;
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
{
if(count<=42)
{
button[i][j]->resize(40,40);
button[i][j]->move(40*j, 40*i);
button[i][j]->show();
controlsLayout->addWidget(button[i][j]);
centralWidget->setLayout(controlsLayout);
setCentralWidget(centralWidget);
count++;
}
}
}
}
Re: Creating an Array of Button
just use a gridlayout for this.
Re: Creating an Array of Button
I hv try it using grid layout also..
Re: Creating an Array of Button
then your doing it wrong.
Alternatively, you could a QVBoxLayout and a QHBoxLayout for each line.
Re: Creating an Array of Button
hello squidge
yeh u r right..its working now by using grid layout..now hw can i decrease the space between each rows..moreever hw can i add textBrowser below..after all buttons are arranged in rows and colums..
my code is:u plz check it..
Code:
selectedDate
=QDate::currentDate();
int count=1,i,j;
[B
]QTextBrowser *T
=new QTextBrowser() //how can i add this text browser below after all the array of buttons are set[/B] for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
{
if(count<=42)
{
button[i][j]->resize(40,40);
button[i][j]->move(40*j, 40*i);
button[i][j]->show();
controlsLayout->addWidget(button[i][j],i,j);
controlsLayout->setSpacing(0);
centralWidget->setLayout(controlsLayout);
setCentralWidget(centralWidget);
count++;
}
}
}
with regards
Anshuman
Re: Creating an Array of Button
I suggest to read some tutorials about layouts...
Re: Creating an Array of Button
hello nish
yeh by using gridlayout its workin now...the only thing is that …hw can i decrease the space between each row…
As i had used all this in my code …but its not working..
QGridLayout::setSpacing()
QGridLayout ::setHorizontalSpacing()
QGridLayout ::setVerticalSpacing()
Re: Creating an Array of Button
The easiest way would be to do the same effect in designer and edit the properties until you get your desired effect and then check the generated output. The designer properties should also give you a clue as to what needs changing.
Or you could just read the documentation of QWidget which QPushButton inherits.
Re: Creating an Array of Button
use setContentMargins() for spacing.