Hi All,

I am trying to achieve something like the following:
flow_Layout_QPushButtons.jpg

Here's my code for it.

Qt Code:
  1. Window::Window()
  2. {
  3. QMainWindow *a= new QMainWindow(this);
  4.  
  5. QWidget *flowWidget = new QWidget();
  6. FlowLayout *flowLayout = new FlowLayout();
  7. flowWidget->setLayout(flowLayout);
  8. int n=20;
  9. QVector <QPushButton *> buttons(n);
  10.  
  11. for (int ii=0;ii<n;ii++)
  12. {
  13. QPushButton * pb = new QPushButton(); // creating buttons
  14.  
  15. pb->setMinimumSize(200,200);
  16. buttons.push_back(pb); // adding buttons to qvector
  17.  
  18. flowLayout->addWidget(pb);
  19.  
  20. }
  21.  
  22. QScrollArea *scroll =new QScrollArea();
  23. scroll->setWidget(flowWidget);
  24.  
  25. a->setCentralWidget(scroll);
  26.  
  27.  
  28. a->show();
  29.  
  30. setWindowTitle(tr("Flow Layout"));
  31. }
To copy to clipboard, switch view to plain text mode 


It seems like flowLayout is not working after the use of scrollArea widget. I want the content of window-2 to be displayed within window-1.
Please suggest how to achieve it?

Thanks!