[Solved]Size of pushbuttons
-
wrote on 27 Jul 2011, 07:01 last edited by
Hello,
I have created an array of buttons, 6x7. I had not specified any size for these while creating them. So they must have been created in some default size.
Now that i have the array of equal sized buttons, I need to find out their size so as to put the images on them. how to i do that? I could not find any function such as, get size or get height or get width.
Thank you
-
wrote on 27 Jul 2011, 07:10 last edited by
"from the docs :":http://doc.qt.nokia.com/4.7/qwidget.html#size-prop
bq. size : QSizeThis property holds the size of the widget excluding any window frame.
bq. If the widget is visible when it is being resized, it receives a resize event (resizeEvent()) immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown.
The size is adjusted if it lies outside the range defined by minimumSize() and maximumSize().
By default, this property contains a value that depends on the user's platform and screen geometry.
Warning: Calling resize() or setGeometry() inside resizeEvent() can lead to infinite recursion.
Note: Setting the size to QSize(0, 0) will cause the widget to not appear on screen. This also applies to windows.
See also pos, geometry, minimumSize, maximumSize, resizeEvent(), and adjustSize(). -
wrote on 27 Jul 2011, 07:11 last edited by
"QPushButton":http://doc.qt.nokia.com/latest/qpushbutton.html extends "QWidget":http://doc.qt.nokia.com/latest/qwidget.html so you can use "geometry()":http://doc.qt.nokia.com/latest/qwidget.html#geometry-prop to retrieve width and height from the returned "QRect":http://doc.qt.nokia.com/latest/qrect.html.
-
wrote on 27 Jul 2011, 07:24 last edited by
eddy,
In the docs, I found,
@
int QSize::height () const @Returns the height.
How do i call the function height()?? using obj of QSize??
This is my code. I jus need to find the height and width of any button
@
cellBut[i][j]=new QPushButton();
connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction()));
@Thank you
-
wrote on 27 Jul 2011, 07:33 last edited by
Just use QPushButton::size(), it's supper base is QWidget
-
wrote on 27 Jul 2011, 07:36 last edited by
What if like that
@cellBut[i][j]->size().height()@ -
wrote on 27 Jul 2011, 07:40 last edited by
chuck,
size function will return what values? With respect to my code, could u tell me how to go about it to find the size of any one of the pushbuttons?
Thank you
-
wrote on 27 Jul 2011, 07:47 last edited by
"size()":http://doc.qt.nokia.com/latest/qwidget.html#size-prop return "QSize":http://doc.qt.nokia.com/latest/qsize.html object, where you can call "height()":http://doc.qt.nokia.com/latest/qsize.html#height
-
wrote on 27 Jul 2011, 07:54 last edited by
rokemoon
:D I got it :D Thank you!!!
Jus one more questions, the values i got was 480 n 640. could you tell me, wats the unit? i mean, mm?? px?? or wat???
Thank you
-
wrote on 27 Jul 2011, 07:56 last edited by
the value in px.
If you solved your problem please mark title of the post like this
[SOLVED] Size of pushbuttions -
wrote on 27 Jul 2011, 08:01 last edited by
I'm sorry alfah, i can not understand your English clearlly. But, the size() function will return the widget's size(as we know QSize), as Eddy mentioned before, i think you need know some concept of geometry/bounding-rect.
[quote author="alfah" date="1311752432"]could u tell me how to go about it to find the size of any one of the pushbuttons?[/quote]
what do you mean alfah ? Can you give us a more detailed description ?
-
wrote on 27 Jul 2011, 08:02 last edited by
ok, you solve it. Good luck :D
-
wrote on 27 Jul 2011, 09:26 last edited by
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
-
wrote on 27 Jul 2011, 09:37 last edited by
did you use an iteration like :
@for(i = 0, i < max , ++i){
for(j=0, j<max, ++j){
//do your stuff
}
}@ -
wrote on 27 Jul 2011, 09:42 last edited by
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.
:( -
wrote on 27 Jul 2011, 09:58 last edited by
I think the problem is, you didn't set the pushbutton's size implicit. And you didn't use any layout management. So the value is not you want.
-
wrote on 27 Jul 2011, 10:04 last edited by
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.
-
wrote on 27 Jul 2011, 10:06 last edited by
chuck,
Yea, I have not set size of the pushbutton, But since it has been created, why doesn it give me the current size of the button. That it should do right?
:( Is it necessary to specify the size of the button while creating them?
Thank you
alfah
-
wrote on 27 Jul 2011, 10:07 last edited by
in case you missed my topic :
have a look at my example. also the QSignalMapper link. -
wrote on 27 Jul 2011, 10:10 last edited by
:) Thanks Eddy,
Got tht one, size now is 100 and 30 which is kinda resonable :)
alfah
1/24