I'm trying to learn to use a QScrollArea, but I'm obviously missing some important step.
Using Qt Creator (or designer, it doesn't matter), I create a QMainWindow and add a QScrollArea. I then drop a standard "Widget" into the QScrollArea (and set its style sheet to "background: red;" just so I can see it), and add a standard push button.
I add the following slot to the button:
(The rest of the code is generated by Creator, but I can provide it if requested.)Qt Code:
void MainWindow::on_pushButton_clicked() { ui->widget->resize(5000, ui->widget->height()); }To copy to clipboard, switch view to plain text mode
My anticipated behavior is: when I click the button, it will re-size the child widget, thereby causing the scroll area to adjust its scroll bars--in this case only the horizontal bar. Unfortunately, that doesn't happen. I can tell that clicking the button does re-size the child widget, but the scroll area's scroll bars do not update--no handles appear, and the entire scroll bar remains gray, as if disabled.
I have tried enabling the scroll bar, with no effect. I ensured widgetResizable is set to false, but that didn't effect the result either. I originally thought a layout I was using for the child widget was causing the problem, but removing it didn't change the result. The way I understand (or maybe misunderstand) the documentation, by default a QScrollArea should respect the size of its child, and adjust the scroll bars automatically. What did I miss?
Bookmarks