Changes in buttons' shapes and positions
Hi guys,
This is a for loop of the code positioning and giving sizes to 22 buttons:
Code:
for(int i=0; i<texts.size(); ++i)
{
connect(button, SIGNAL(clicked(bool)),
signalMapper, SLOT(map()));
button -> setFixedSize(50,30);
signalMapper -> setMapping(button, texts[i]);
gridLayout -> addWidget(button, i/5, i%5);
}
The image is in the following link:
http://uploads.im/BCXZu.jpg
First I want to change the position of the buttons. For example arrange them. And make some ones smaller/bigger that other ones.
Then to give the buttons some colors to appear nice.
How to do these please? Should I firstly remove the gridlayout?
I wrote the app only in C++ code and didn't use the Designer.
1 Attachment(s)
Re: Changes in buttons' shapes and positions
You can use more then one layout (layout in layout). One QGridLayout for digits, second for operators (sum, divide etc.).
For labels Operations, Results and QLineEdits use QFormLayout. Something like this.
Re: Changes in buttons' shapes and positions
Thank you for the reply, but I want to manipulate the size, position, color and the font of each button manually. I think I need to somehow take back the buttons from signalMapper so that I will be able to do the work above on then.
Re: Changes in buttons' shapes and positions
Instead of throwing away the value of "button" on every pass through your loop, make a QList< QPushButton * > or QVector< QPushButton * > as a member of your class and save them there.
Code:
// in class definition: QVector< QPushButton * > myButtons
myButtons.clear();
for(int i=0; i<texts.size(); ++i)
{
connect(button, SIGNAL(clicked(bool)),
signalMapper, SLOT(map()));
button -> setFixedSize(50,30);
signalMapper -> setMapping(button, texts[i]);
gridLayout -> addWidget(button, i/5, i%5);
myButtons.push_back( button );
}
Now that you have saved the button pointers, you can do whatever you want with the button properties. Of course, with fixed size buttons, changing the font will probably result in undesired effects (like the text becoming too big for the button). Why not let the layout do what it is designed to do, and allow the buttons to shrink and grow as the grid does?
Re: Changes in buttons' shapes and positions
You can use something like this for customized shapes, images etc.
Code:
QPixmap pixmapLogin
(":/new/prefix1/Resources/login_released.png");
QSize imagesize
= pixmapLogin.
size();
ui->LoginButton->setFixedSize(imagesize);
ui->LoginButton->setMask(pixmapLogin.mask());
ui
->LoginButton
->setCursor
(QCursor(Qt
::PointingHandCursor));