I've found a satisfactory solution. I found out the horizontalScrollBar->maximum changes with each successive paint event. I can calculate what the maximum should be and then determine which is the last paint event.
A layout can not be hidden since they are not widgets and does not have a setVisible() function.
You have to create a widget that you can hide, that contains the layout and the other widgets that should be hidden, then you hide the widget instead of the layout.
QWidget* myWidget = new QWidget();
QHBoxLayout * layout = new QHBoxLayout(myWidget);
layout->addWidget(new QLabel("Label"));
myWidget->setVisible(false);