I have a window and a bunch of push buttons. This window will be my "Main Menu". After placing the buttons, I would like to have these buttons fixed to the size of this window. So they should fill the window and change their size if the window changes his (by the user for instance).

How do I do that?

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top