开发者

Adding scroll bar to widget containing a layout in QT C++

开发者 https://www.devze.com 2023-03-20 13:28 出处:网络
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

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!


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号