Qt 动态添加checkbox,并添加点击事件


 1 void AddCheckBox()
 2 {
 3   QStringList list;
 4   list<<"one"<<"two"<<"three";
 5   foreach(QString number,list)
 6   {
 7     QCheckBox *button = new QCheckBox(number,this); //widget添加button
 8     connect(button,SIGNAL(clicked()),this,SLOT(getButtonText()));
 9   }
10 }
11 void getButtonText()
12 {
13   QCheckBox *button = (QCheckBox * )(sender()); //关键一步是利用sender()
14   qDebug()<<"button text:"<<button->text();
15 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM