You should put your buttons in a layout (see for instance QGridLayout
or QVBoxLayout
).
Example (assumes that window
is your window, and button
is your button):
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(button);
window->setLayout(layout);
This will make the button(s) expand horizontally. Would you like them to expand vertically as well, you need to change the vertical size policy of the button(s) as the default vertical policy for a button is to not use up more space than its preferred size.
button->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);