Layout类中没有直接的swap方法,但是通过其他方法的组合就可以实现交换layout中控件的交换

 1     QWidget *w1 = anibutton[1],*w2 = anibutton[3];
 2     int p1 = ui->horizontalLayout->indexOf(w1);
 3     int p2 = ui->horizontalLayout->indexOf(w2);
 4     qDebug()<<"p1"<<p1;
 5     qDebug()<<"p2"<<p2;
 6     if(p1>p2)std::swap(p1,p2);
 7     ui->horizontalLayout->removeWidget(w1);
 8     ui->horizontalLayout->removeWidget(w2);
 9     ui->horizontalLayout->insertWidget(p1,w2);
10     ui->horizontalLayout->insertWidget(p2,w1);

 

相关文章:

  • 2021-10-21
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-12-18
  • 2021-11-19
猜你喜欢
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案