[PyQt] PyQt4 question about type-to-select in numeric drop-down lists

David Boddie david at boddie.org.uk
Tue Aug 27 21:44:38 BST 2013


On Tue Aug 27 15:53:59 BST 2013, Sarah Mount wrote:

> sorry if this is a bit of a n00b question, but hopefully someone can
> clarify a misunderstanding for me. I am working with some colleagues on a
> Python2.x PyQt4 project and the GUI for this software has several drop-down
> lists where each entry in the list is an integer, in numerical order. We
> have had a (reproducible) bug report about these.

No problem. Sometimes what seems to be the simplest things can have
surprising behaviour.

> When a user clicks on the drop-down and types a number, the drop-down
> scrolls to select that number. So, [contrived example] if the drop-down
> contains entries 0-1000 and the user types 23, the drop-down scrolls to
> reveal 23 (if necessary) and selects that entry on the list. So far, so
> standard.
> 
> If the user selects a number with repeated digits, i.e. any multiple of 11
> (in reality only tested on numbers <100) the wrong number is selected. For
> example, if I open a drop-down and type "77" "70" gets selected. Is this
> some obvious bug in the way we have configured our GUI or have I
> misunderstood something really basic?

No, I think it's a bug in Qt, and probably in QAbstractItemView because
that's what is providing the underlying list logic in the drop-down menu.
The behaviour seems to be that the string used to search the data is checked
to see if it is simply the same first character repeated throughout the
string (e.g., "aaa" or "333") and handled specially. This seems to completely
break the regular behaviour: if you try "77", it won't work, but "776" will
cause it to navigate to the correct item.

If anyone wants to sanity check my reasoning, I think the problem is in
QAbstractItemView::keyboardSearch().

I can't immediately suggest a workaround. My instinct would be to use a
completer to influence the way QComboBox finds items but I don't know if
that will help, especially when the drop-down is open.

David


More information about the PyQt mailing list