c++ - Fit the width of the view to longest item of the QComboBox -
i've got qcombobox
contains long strings. long means strings wider width of qcombobox
on gui
. in case qt
display items in way:
previously working matlab
has less user friendly gui
drop-down list think matlab
solution better:
is there easy way achieve similar result in qt
or have setup custom model , view purpose ?
i've done few years back. should working fine.
//determinge maximum width required display names in full int max_width = 0; qfontmetrics fm(ui.comboboxnames->font()); for(int x = 0; x < nameslist.size(); ++x) { int width = fm.width(nameslist[x]); if(width > max_width) max_width = width; } if(ui.comboboxnames->view()->minimumwidth() < max_width) { // add scrollbar width , margin max_width += ui.comboboxnames->style()->pixelmetric(qstyle::pm_scrollbarextent); max_width += ui.comboboxnames->view()->autoscrollmargin(); // set minimum width of combobox drop down list ui.comboboxnames->view()->setminimumwidth(max_width); }
Comments
Post a Comment