Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Why editable QComboBox using pySide6 is not case sensitive?
Forum Updated to NodeBB v4.3 + New Features

Why editable QComboBox using pySide6 is not case sensitive?

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 1 Posters 363 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrAWD
    wrote on 14 Feb 2025, 16:32 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MrAWD
      wrote on 14 Feb 2025, 19:09 last edited by
      #2

      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!

      1 Reply Last reply
      2
      • S SGaist has marked this topic as solved on 14 Feb 2025, 19:46

      1/2

      14 Feb 2025, 16:32

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved