qt - How to add different types of delegates in QTreeView -


i want create same kind of qtreeview (not qtreewidget) structure shown in attached figure.. property editor of qt. using qt-4.6

enter image description here

on 2nd column, depending on different condition, can have either spin box, or drop down or checkbox or text edit... , on... please guide me on how set different delegates in different cells of particular column. docs, evident there no straight away api setting delegate on cell (rather available full widget or row or column).

all qabstractitemdelegate methods, createeditor or paint, have model index 1 of parameters. can access model data using index , create appropriate delegate widget. when create model should set value every item used distinguish type.

an example:

enum delegatetype {     dt_text,     dt_checkbox,     dt_combo }  const int mytyperole = qt::userrole + 1;  qstandarditemmodel* createmodel() {     qstandarditemmodel *model = new qstandarditemmodel;      qstandarditem *item = new qstandarditem;     item->settext("hello!");     item->setdata(dt_checkbox, mytyperole);      model->appendrow(item);      return model; }  qwidget* mydelegate::createeditor(qwidget *parent,                                    const qstyleoptionviewitem &option,                                    const qmodelindex &index) const {     int type = index.data(mytyperole).toint();      // simplified example     switch (type)     {     case dt_text:         return new qlinededit;     case dt_checkbox:         return new qcheckbox;     case dt_combo:         return new qcombobox;     default:         return qitemdelegate::createeditor(parent, option, index);     } } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -