There is a table layout with 12 text fields (four rows of three fields). How to implement, so that by pressing Tab, switching went not horizontally, but vertically?

for (int i = 0; i < 11; i++) setTabOrder(ui->gridLayout->itemAt(i)->widget(), ui->gridLayout->itemAt(i + 1)->widget()); 

How to do the same for columns only?

  • QWidget :: setTabOrder , not? - Fat-Zer
  • @ Fat-Zer This is understandable and I even wrote it in the title, but the algorithm is not very. - a6461
  • I can not imagine what exactly here can cause difficulties ... the code of creating widgets / layout in the studio ... - Fat-Zer

1 answer 1

Somehow you can:

 int col = ui->gridLayout->columnCount(); int row = ui->gridLayout->rowCount(); for (int j = 0; j < col; j++) { for (int i = 0; i < row-1; i++) { setTabOrder (ui->gridLayout->itemAtPosition (i, j)->widget(), ui->gridLayout->itemAtPosition (i, j+1)->widget()); } if (i != col-1) { setTabOrder (ui->gridLayout->itemAtPosition (i, row-1)->widget(), ui->gridLayout->itemAtPosition (i+1, 0 )->widget()); } } 

Checking that in layout 'ah really QWidget ' s omitted.

Also, the switching order can be set directly in the designer.