在 QT C++ 中向包含布局的小部件添加滚动条
我是 QT 新手,正在创建一个具有网格布局的小部件。网格布局包含 QLineEdit 小部件的矩阵。窗口会调整大小以适应布局,但当布局较大时,它会超出屏幕。当我最大化屏幕时,QLineEdit 小部件会调整大小以适合屏幕,对于大型布局,它们会变得非常小。
我希望能够在不调整 QLineEdit 小部件大小的情况下调整窗口大小,并添加滚动条进行导航。
我尝试了以下操作,但没有成功:
Window->resize(QSize(500,500));
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setWidget(Window);
其中 window 是包含布局的小部件。此外,执行“scrollArea->setWidget(Window);”后窗口将关闭我不知道为什么。
如果有人可以帮助我,我将非常感激。
谢谢你!
I am new to QT and I am creating a widget that has a gridlayout. The gridlayout contains a matrix of QLineEdit widgets. The window resizes to fit the layout but when layout is large it goes off screen. When I maximize the screen, the QLineEdit widgets are resized to fit the screen and for large layouts they become extremely small.
I want to be able to resize the window without resizing the QLineEdit widgets and add scroll bars to navigate.
I tried the following with no luck:
Window->resize(QSize(500,500));
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setWidget(Window);
where window is the widget containing the layout. Also, the window closes when after executing "scrollArea->setWidget(Window);" and I dont why.
If someone can help me out I would really appreciate it.
Thank You!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要禁用小部件上的垂直调整大小,为什么不在小部件上使用 setFixedHeight() 方法呢?
对于菜单栏,为什么不把它从可滚动的小部件中取出来呢。您可以为包含菜单栏的窗口布局,然后为包含其他所有内容(可滚动部分)的小部件。这就是您要找的吗?
For disabling the vertical resize on the widgets, why don't you just use the setFixedHeight() method on the widgets?
For the menu bar, why don't you take it out of the widget that is scrollable. You can have a layout for the window that contains the menu bar and then the widget that contains everything else (scrollable part). Is that what you are looking for?
我通过使用菜单栏创建 QMainWindow 解决了我的问题。然后创建一个包含布局的小部件,将滚动区域设置为小部件。最后将主窗口的中央小部件设置为滚动区域。
I fixed my problem by creating a QMainWindow with the menu bar. Then created a widget which includes the layout, set the Scroll Area to the widget. Finally set the central widget of the main widow to the scroll area.