Qt Code:
  1. QWidget *w = new QWidget(this);
  2. QGridLayout *grid = new QGridLayout();
  3. ui->scrollArea->setWidget(w);
  4. // this->setFixedSize(this->geometry().width(),this->geometry().height());
  5.  
  6.  
  7. QMap<int,QPushButton*> mapp;
  8. for(row=0;row <= 49 ;row++)
  9. {
  10.  
  11. QPushButton *pb = new QPushButton(w);
  12. grid->addWidget(pb, row/4, row%4);
  13. pb->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding);
  14.  
  15. }
  16.  
  17. w->setLayout(grid);
To copy to clipboard, switch view to plain text mode 

Here it is

when I have tried
centralWidget()->setLayout(grid);
it ll shrink with window size but it wont fit in to the layout