c++ - Qt set a custom widget inside a QTableView -
i need put custom widget inside qtableview
cell subclassed qabstracttablemodel
.
i searched given solutions no 1 catch needs. custom widget must stay here time , not in editing mode qitemdelegate::createeditor
. custom widget may everything, i'm searching general solutions widget not qpushbuttons
or qcheckbox
.
sorry english.
you can use qabstractitemview::setindexwidget
, overriding qabstractitemview::datachanged
achieve want follows:
class mytableview : public qtableview { protected: void datachanged(const qmodelindex &topleft, const qmodelindex & bottomright, const qvector<int> & roles) { qpushbutton *ppushbutton = qobject_cast<qpushbutton*>(indexwidget(topleft)); if (ppushbutton) ppushbutton->settext(model()->data(topleft, qt::displayrole).tostring()); else qtableview::datachanged(topleft, bottomright, roles); } }; void main () { mytableview table; table.setcellwidget(table.model()->index(0, 0, qmodelindex()),new qpushbutton()); }
note incomplete implementation, should show how can solve problem. real implementation should update qpushbutton between topleft , bottomright.
Comments
Post a Comment