c++ - QComboBox - set selected item based on the item's data -
what best way of selecting item in qt combo box out of prefined list of enum based unique values.
in past have become accustomed .net's style of selection item can selected setting selected property item's value wish select:
cboexample.selectedvalue = 2; is there anyway qt based on item's data, if data c++ enumeration?
you lookup value of data finddata , use setcurrentindex
qcombobox* combo = new qcombobox; combo->additem("100",100.0); // 2nd parameter can qt type combo->additem ..... float value=100.0; int index = combo->finddata(value); if ( index != -1 ) { // -1 not found combo->setcurrentindex(index); }
Comments
Post a Comment