[Solved]Size of pushbuttons
-
Hey everybody,
im sorry to restart this thread, but the following code gives me values 480 and 640
@
cellBut[i][j]=new QPushButton();
connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction()));
ht=cellBut[0][0]->size().height();
wd=cellBut[0][0]->size().width();
@by no means this is the size of the buttons, think its the screen size!!!!
I need pushbutton ht and width
Thank you
-
eddy,
Yup i did,
@
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(onClickAction())); ht=cellBut[i][j]->size().height(); wd=cellBut[i][j]->size().width(); } }
@
ht and wd gives me 640 and 480 respectivvely. which i think is the screen size and not individual button size.
:( -
what Chuck is saying is that you didn't use a parent or add them to a layout. That way they get a size.
have a look at this quick and dirty example:
@ int rows = 6;//this is convenient in case you want to alter the numbers
int cols = 7;
QPushButton* cellBut[rows][cols] ;for(int i=0;i<rows;i++) { for(int j=0;j<cols;j++) { cellBut[i][j]=new QPushButton(this); //remark the use of a parent here // connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction()));//better way see below } } qDebug() << cellBut[0][0]->size().height(); qDebug() << cellBut[0][0]->size().width();@
you might have a look at "QSignalMapper":http://doc.qt.nokia.com/4.7/qsignalmapper.html#details. There is a nice example of what you try to achieve.
-