Reputation: 13406
How can I add a scroll bar to a QMainWindow
, when this QMainWindow
contains just one central widget, which is bigger than the QMainWindow
size?
So that the scroll bar can be used to see different parts of this central widget.
Upvotes: 3
Views: 6746
Reputation: 5510
For some reason the child widget would not render at all if it was a QWidget
with a layout. It only worked after calling setWidgetResizable(true)
.
auto mainWidget = new QWidget();
auto scrollArea = new QScrollArea();
scrollArea->setWidget(mainWidget);
scrollArea->setWidgetResizable(true);
setCentralWidget(scrollArea);
resize(1470, 900);
QHBoxLayout* mainLayout = new QHBoxLayout(mainWidget);
...
Upvotes: 0
Reputation: 2268
Set the central widget of your QMainWindow
to a QScrollArea
and then set the widget of that new QScrollArea
to the widget that was previously your central widget.
Remember to set the "widget resizable" property of QScrollArea to true.
Upvotes: 4