qt - Synchronize QTableWidget cell with widget in the center of the cell -
i utilize qcheckbox
in qtablewidgetcell
qwidget *widget = new qwidget(); qcheckbox *checkbox = new qcheckbox(); qhboxlayout *layout = new qhboxlayout(widget); layout->addwidget(checkbox); layout->setalignment(qt::aligncenter); layout->setcontentsmargins(0, 0, 0, 0); widget->setlayout(layout); table->setcellwidget(0, 0, widget);
the result of code cell checkbox in center.
i need create checkbox reaction mouse moving , clicking in empty area when cursor under checkbox.
if dont want fullblown functionality of qcheckbox
checkmark, can utilize simple qtablewidgetitem
, modify checkstate.
qtablewidgetitem* item = new qtablewidgetitem(); item->setcheckstate(qt::unchecked); table->setitem ( 0, 0, item ); connect(table, signal(cellclicked(int , int )), this, slot(onclicked( int, int))); void onclicked( int row, int column ) { if(row != checkablelerow && col != checkablelecol ) return; // or else item = table->item(row, column); item->setcheckstate(item->checkstate() == qt::checked ? qt::unchecked : qt::checked); }
now whole cell checkable. code may need refinement.
qt qtablewidget qt-signals qcheckbox
No comments:
Post a Comment