[PyQt] QComboBox replacing edit text if case differs from existing item.

concentricpuddle concentricpuddle at gmail.com
Sun Oct 17 21:01:54 BST 2010


Hi

I'm having a problem with QComboBox not allowing me to change the edit
text to anything existing item of differing case.

Example code is below. What I'd like to do is enter 'one' into a combo
box already containing the item 'One' without the side effect of the
text being changed to 'One'. Currently it's changed back to 'One' as
soon as the combo box loses focus.

Disabling AutoCompletionCaseSensitivity works, but it has the side
effect of not being useful (Doesn't eg. show completions for 'one').

I've also tried overriding the focusOutEvent of QComboBox and
restoring the correct text, but then things like copy-paste don't
work. Changing the completer hasn't helped any either.

The fact combo boxes behave this way is detrimental to my app. If
anyone has any ideas (or I missed something obvious), please let me
know.

I'm using Qt 4.6.2 and PyQt 4.7.2 on Ubuntu 10.04, but have
experienced this on other distros/Qt versions above 4.5.

Thanks and Regards

Code
-----------------------------

from PyQt4.QtGui import *
from PyQt4.QtCore import SIGNAL, Qt

class Widget(QWidget):
    def __init__(self, parent=None):
        super(Widget, self).__init__(parent)
        combo = QComboBox()
        combo.setEditable(True)
        combo.addItems(['One', 'Two', 'Three'])
        lineedit = QLineEdit()

        layout = QVBoxLayout()
        layout.addWidget(combo)
        layout.addWidget(lineedit)
        self.setLayout(layout)

app = QApplication([])
widget = Widget()
widget.show()
app.exec_()


More information about the PyQt mailing list