Qt dynamically generated controls

Abstract:
Realization function: according to the input number, dynamically add the corresponding number of buttons.
I referenced a lot of blog posts in the beginning, the content is uneven, here I will share the core code with everyone, if you have questions, I hope to communicate more.
Implementation process:
Use the layout function to dynamically generate controls and add them to the layout, and then pass the layout to the container for display

//首先使用布局,将每一个要显示的控件添加进来
 QHBoxLayout *qhbl = new QHBoxLayout();
  for (size_t i = 0; i < num; i++)
  {
   CoilInforn *w = new CoilInforn();   //动态生成控件
  qhbl->addWidget(w);//将控件添加到布局中
  }
  //容器显示布局
  ui.groupbox_main->setLayout(qhbl);

Three custom controls dynamically generated
Insert picture description here

Published 22 original articles · Likes2 · Visits 1157

Guess you like

Origin blog.csdn.net/qinqinxiansheng/article/details/105038101