[Qt-interest] QComboBox with a 'no item'?

Robert Hairgrove evorgriahr at hispeed.ch
Sun Jun 6 10:18:21 CEST 2010


Timothy Reaves wrote:
> I'm using a QComboBox backed by a model.  This forces the user to
> always have an item selected, once one is selected.   Initially, the
> index is set to -1, so no item is selected.  Once an item is
> selected, there is no way to select a blank item.  I could put a
> little button next to each combo box the clear the selection (setting
> the index to -1), but this seems a common issue.  Is there a way to
> do this with the model or the combo box itself?
> 
> Thanks.

I usually do this with the model. As I see it, the "(no selection)" item
IS actually a meaningful selection. How you deal with it depends largely
on your model (e.g. maybe a database table), so that seems to be the
logical place to put it, usually corresponding to a default value of
some sort.



More information about the Qt-interest-old mailing list