[Qt-interest] Set a constraint on QComboBox [Make every item unique]
Mark Summerfield
list at qtrac.plus.com
Sun Mar 14 08:36:43 CET 2010
On 2010-03-13, Aaron Lewis wrote:
> Hi,
> How can i make a QComboBox has no same entries ? I mean to set an
> restrict.
>
> If there's no such functions , i'd have to create one myself. (Before
> inserting into it , check the constraint)
>
> Will appreciate your help ;-)
You could create a custom QSortFilterProxyModel and set that as the
QComboBox's model. And in the custom model, keep a cache of entries
you've already seen in a QSet (at some cost in memory depending on how
many unique entries there are). Then you just populate the custom model
instead of directly populating the QComboBox, and rely on your
reimplementation of filterAcceptsRow() to ensure that duplicates are
ignored. I describe this approach in Chapter 3 of my forthcoming book
_Advanced Qt Programming_.
--
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
C++, Python, Qt, PyQt - training and consultancy
"Advanced Qt Programming" - ISBN 0321635906
More information about the Qt-interest-old
mailing list