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