How to set QScrollArea centralWidget ?
-
I need QScrollArea.size fit MainWindow.size when resize.
MainWindow { resize(600,400); QWidget *widget = new QWidget; widget->setMinimumSize(1000,260); setCentralWidget(widget); QScrollArea *scrollArea = new QScrollArea(this); scrollArea->setWidget(widget); scrollArea->setFixedSize(500,260); }
-
@sonichy said in How to set QScrollArea centralWidget ?:
scrollArea->setFixedSize(500,260);
Then why do you set fixed size?
-
Hi,
What don't you set the QScrollArea as central widget of your QMainWindow ?
-
@SGaist
I'm interested: is the code as stands "allowed"?QMainWindow
has itscentralWidget
set to a widget, and then theQScollArea
sets as its widget theQMainWindow::centralWidget
. So presently the scroll area has been placed "outside" the main window's central widget. We have separateQMainWindow->QWidget
andQScrollArea->QWidget
. Are you allowed to create aQScrollArea
and then just "put it on" some existing widget in the hierarchy (without actually inserting it into the hierarchy so that it becomesQMainWindow->QScrollArea->QWidget
)? -
You can have floating widgets. The thing that is wrong here is that "widget" is set as the QMainWindow and as the QScrollArea "central widget". From the description it should just be:
- Create widget
- Create QScrollArea
- Set widget in QScrollArea
- Set scroll area as QMainWindow central widget
-
@SGaist
Absolutely, that is what @sonichy should do. That is hierarchyQMainWindow->QScrollArea->QWidget
.But from what he originally wrote and what you say. if I have an existing hierarchy of widgets, if I feel like it I am allowed to just go
QScrollArea::setWidget()
to some widget already there, without actually inserting myQScrollArea
, and that is allowed? I can add scrolling to any widget that way and it works? -
Some widget already inherit from QScrollArea, so no need for them but otherwise that's the idea yes.