gpt4 book ai didi

c++ - Qt:自动向QGroupbox添加滚动条

转载 作者:行者123 更新时间:2023-11-28 05:10:19 26 4
gpt4 key购买 nike

我想在调整具有此组框的对话框窗口大小时(使其变小)自动将滚动条添加到标签组框,以便保持组框内容的相同 View 并在该对话框时通过滚动查看它很小。

QGroupBox* GroupBox = new QGroupBox;
QVBoxLayout *Layout = new QVBoxLayout;
Layout->addWidget(Label1);
Layout->addWidget(Label2);
Layout->addWidget(Label3);
Layout->addWidget(Label4);
GroupBox ->setLayout(Layout);

我已经尝试了以下但它不起作用。

QScrollArea* scrollArea = new QScrollArea(this);
scrollArea->setWidget(GroupBox);

最佳答案

我想分享我找到的问题的答案:答案是添加 2 个组框和 2 个布局,并将滚动区域作为小部件添加到第二个布局。代码将是:

QGroupBox* GroupBoxIn = new QGroupBox;
QVBoxLayout *LayoutIn = new QVBoxLayout;
QGroupBox *GroupBoxOut = new QGroupBox;
QVBoxLayout *LayoutOut = new QVBoxLayout;
QScrollArea* scrollArea = new QScrollArea();

LayoutIn ->addWidget(Label1);
LayoutIn ->addWidget(Label2);
LayoutIn ->addWidget(Label3);
LayoutIn ->addWidget(Label4);

GroupBoxIn ->setLayout(LayoutIn );
scrollArea->setWidget(GroupBoxIn );
scrollArea->setWidgetResizable( true );
LayoutOut ->addWidget(scrollArea);
GroupBoxOut ->setLayout(LayoutOut );

关于c++ - Qt:自动向QGroupbox添加滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43659089/

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