gpt4 book ai didi

Qt: "Expanding"在布局中不起作用

转载 作者:行者123 更新时间:2023-12-04 12:53:52 33 4
gpt4 key购买 nike

我的目的是创建一个带有 QVBoxLayout 的可滚动控件,上面有各种控件(比如按钮)。该控件放在 *.ui 窗体上。在该控件的构造函数中,我编写了以下代码:

    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);
}

我的问题:按钮具有固定大小并且不会水平展开。他们有一个固定的大小。我希望它们水平扩展以填充它们所在的行。如何让它们在父容器中水平扩展?

最佳答案

尝试调用 this->setWidgetResizable(true);

关于Qt: "Expanding"在布局中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10905151/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com