I added some pushbuttons and deleted the menu bar and toolbar in the main window.
After running, I found that if I resize, the window scroll-bars don't appear.
I don't want the pushbuttons to resize or move. I am fine with them becoming invisible, but I want the scrollbars, so that the user can scroll to the invisible parts.
So, I added a scroll area widget. When I increase the size of the scroll area up to the window size; after running, the window appears blank. Maybe the push-buttons go 'below' the scroll-area. How do I change which object should be on 'top'?
I used the setCentralwidget(ui->scrollareacontentswidget);
, and tried deleting the centralwidget
, but I can't.
A QWidget does not have scrollbars, you need to add a zone which will have scrollbars.
Just add a QScrollArea to your window, and put all the widgets in it (buttons, etc...). Don't forget to layout your scroll area to the whole main window.
More precisely, the hierarchy is something like that:
main window central widget (with a layout)
scroll area
scroll area widget (with a layout, layout scroll area if you're in the designer)
your container widget (should be layouted also)
your buttons, layouts, etc...
((with a layout)
= layout the widget with a layout, but the type of the layout doesn't matter, since only one widget needs to be layouted).
Your container widget should be layouted as you want, spacers can be useful.