3
我的目的是创建一个带有QVBoxLayout的可滚动控件,它内部有各种控件(比如按钮)。该控件放置在* .ui表单中。在构造该控件我写了下面的代码:Qt:“扩展”不适用于布局
MyScrollArea::MyScrollArea(QWidget *parent) :
QScrollArea(parent)
{
// create the scrollable container
this->container = new QWidget(); // container widget member
this->container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->container->setContentsMargins(QMargins(0,0,0,0));
this->content = new QVBoxLayout(); // layout member
this->content->setMargin(0);
this->content->setSpacing(0);
for (int i=0; i<100; i++)
{
QPushButton * widget = new QPushButton();
widget->setText("button");
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
this->content->addWidget(widget);
}
this->container->setLayout(this->content);
this->content->layout();
this->setWidget(this->container);
}
我问题:按钮具有固定的大小和不水平扩大。他们有一个固定的大小。我希望他们水平扩展以填充他们所在的行。我如何让他们水平扩展父容器?
对于布局中的每个小部件都带有“setMinimumHeight”技巧。谢谢。 – JasonGenX