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.
// 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 );
}
// in class definition: QVector< QPushButton * > myButtons
myButtons.clear();
for(int i=0; i<texts.size(); ++i)
{
QPushButton* button = new QPushButton(texts[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 );
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks