Loop for creating button in multiple row and column

时间:2017-09-30 15:43:14

标签: c++ qt qvboxlayout

From this code, I want to create a table of buttons followed by input (row, column).

But my GUI doesn't show the buttons in 2x4, it shows them in 1x8.

QHBoxLayout* hl = new QHBoxLayout;
QVBoxLayout* vl = new QVBoxLayout;
for(int i=0; i<4; i++){
  for(int j=0; j<2; j++){
    btn_list.append(new QPushButton(this));
    hl->addWidget(btn_list[(i*2)+j]);
  }
  vl->addLayout(hl);
}
this->setLayout(vl);

Rendered output: Screenshot

0 个答案:

没有答案