Why editable QComboBox using pySide6 is not case sensitive?
-
So, I have this strange problem that editable QComboBox widget is case insensitive. Here is a simple application that shows the problem:
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QComboBox, QPushButton class ComboBoxApp(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Editable QComboBox Example") self.setGeometry(100, 100, 300, 100) # Create a QVBoxLayout instance layout = QVBoxLayout() # Create an editable QComboBox self.combo_box = QComboBox() self.combo_box.setEditable(True) # Create a QPushButton self.button = QPushButton("Send") self.button.clicked.connect(self.save_entry) self.fakeButton = QPushButton("Fake") # Add widgets to the layout layout.addWidget(self.combo_box) layout.addWidget(self.button) layout.addWidget(self.fakeButton) # Set the layout for the main window self.setLayout(layout) # List to store entries self.entries = [] def save_entry(self): entry = self.combo_box.currentText() if entry and entry not in self.entries: if len(self.entries) >= 5: self.entries.pop(0) self.entries.append(entry) self.combo_box.addItem(entry) if __name__ == "__main__": app = QApplication([]) window = ComboBoxApp() window.show() app.exec()
Here we have an editable combo box that stores those entries into the list. But, after entering a string "first" and pressing Send button, which stores that entry into the list, if I change the text to "First", as soon as I click on any other widget like Fake button for example, which is not connected to anything) , "First" changes it "first". Since this is needed to send case sensitive commands, how can I make it not to switch to previous entry.
It looks like that this is changed on combo box loose of focus event, but how to prevent changing that entered text?
-
Found solution for this problem!
By default, QCompleter object is set to CaseInsensitive and that is what was setting it to the previous entry. With an addition of line like this:
self.combo_box.completer().setCaseSensitivity(Qt.CaseSensitivity.CaseSensitive)
things are working correctly!
-
S SGaist has marked this topic as solved