如何向父QWidget添加滚动条
我了解如何将滚动区域添加到特定的小部件。然而,就我而言,Qwidget 有多个子小部件,这些小部件都是使用 QVBoxLayout 设置的。现在在这种情况下如何添加滚动条?这里 QWidget 不是中心小部件,它是 TabWidget 的页面之一。我的代码如下所示:
QTabWIdget *center = new QTabWidget; setCentralWIdget(center);
xTab = new QWidget;
formLayout = new QFormLayout; formLayout->addWidget(...); formLayout->addWidget(...); formLayout->addWidget(...); formLayout->addWidget(...);
xTab->setLayout(formLayout);
现在如何将滚动条设置为 xTab?我尝试使用
scrollArea = new QScrollArea;
scrollArea->setWidget(xTab);
但是,这不起作用。
任何想法/建议都是有帮助和赞赏的。
I understand how to add a scrollArea to a particular widget. However in my case Qwidget has multiple child widgets and these are all set using QVBoxLayout. Now how can I add a scroll bar in this case? Here QWidget is not the center widget, its one of the pages of the TabWidget. My code looks like:
QTabWIdget *center = new QTabWidget; setCentralWIdget(center);
xTab = new QWidget;
formLayout = new QFormLayout; formLayout->addWidget(...); formLayout->addWidget(...); formLayout->addWidget(...); formLayout->addWidget(...);
xTab->setLayout(formLayout);
Now how can I set the scrollBar to xTab? I tried using
scrollArea = new QScrollArea;
scrollArea->setWidget(xTab);
however, this isn't working.
Any idea/suggestions are helpful and appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过使用
QScrollArea
作为标签页?Have you tried using
QScrollArea
as the tab page?我使用以下方法取得了成功:
QScrollArea 定义了可滚动小部件将出现的位置。如果parent为0,则它是一个非模态窗口。 setGeometry 将 QScrollArea 实例设置为所需的尺寸(选项卡的尺寸)。 setWidget 定义 QScrollArea 将实际滚动的小部件。
I had success using the following:
The QScrollArea defines where the scrollable widget will appear. If parent is 0, it's a non-modal window. setGeometry sets the QScrollArea instance to the desired dimensions (that of the tab). setWidget defines what widget the QScrollArea will actually be scrolling.