Hi,

I have a problem with a scroll area for a QWidget when contents get
changed dynamically, e.g,., added to that QWidget after the setWidget
call for the QScrollArea. Instead of a lengthy explanation, here is a
simple example:

Qt Code:
  1. --- Example.cpp ---
  2. #include <QApplication>
  3. #include <QWidget>
  4. #include <QGridLayout>
  5. #include <QPushButton>
  6. #include <QScrollArea>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. QApplication app(argc, argv);
  11. QWidget *test = new QWidget;
  12. QScrollArea area(0);
  13. area.setWidget(test); // A
  14. QGridLayout gl(test);
  15. gl.setSpacing(0);
  16. gl.setMargin(0);
  17. QPushButton b0("1", test);
  18. gl.addWidget(&b0,0,0);
  19. QPushButton b1("2", test);
  20. gl.addWidget(&b1,0,1);
  21. QPushButton b2("3", test);
  22. gl.addWidget(&b2,1,0);
  23. QPushButton b3("4", test);
  24. gl.addWidget(&b3,1,1);
  25. QPushButton b4("5", test);
  26. gl.addWidget(&b4,2,0);
  27. QPushButton b5("6", test);
  28. gl.addWidget(&b5,2,1);
  29. // area.setWidget(test); // B
  30. area.show();
  31. return app.exec();
  32. }
  33. --- Example.cpp ---
To copy to clipboard, switch view to plain text mode 

If I first call setWidget() to put the widget into the QScrollArea and
then add sub-widgets, e.g., QPushButtons then the QWidget displayed in
the QScroll area is empty. Everything works fine if I comment out the
setWidget() call marked "A" and call setWidget() at location"B". However,
I do have a set up where I want to make changes to the QWidget based
on user interaction where it is no longer an option to do the
setWidget() call after changes. Is there a proper way to notify the
QScrollArea about the fact that the QWidget it contains has changed?

Thank you for any help