c++ - QTableWidget Checkbox get state and location -


how state of checkbox , row , column of checked? onclick pushbutton function.

    qtablewidget *t = ui->tablewidget;     t->setrowcount(2);     t->setcolumncount(2);      qstringlist tableheader;     tableheader<<"item01"<<"item02";     t->sethorizontalheaderlabels(tableheader);      (int = 0; < t->rowcount(); i++) {         (int j = 0; j < t->columncount(); j++) {             qwidget *pwidget = new qwidget();             qhboxlayout *playout = new qhboxlayout(pwidget);             qcheckbox *pcheckbox = new qcheckbox();             playout->setalignment(qt::aligncenter);             playout->setcontentsmargins(0,0,0,0);             playout->addwidget(pcheckbox);             pwidget->setlayout(playout);             t->setcellwidget(i, j, pwidget);         }     } 

and when clicked button, need selected elements rows, columns of each.

void widget::on_pushbutton_clicked() {      // code here          // example: selected ["item01", 2] } 

i iterate on cell widgets:

for (int = 0; < t->rowcount(); i++) {     (int j = 0; j < t->columncount(); j++) {         qwidget *pwidget = t->cellwidget(i, j);         qcheckbox *checkbox = pwidget->findchild<qcheckbox *>();         if (checkbox && checkbox->ischecked())             qdebug() << t->horizontalheaderitem(j)->text() << i;     } } 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -