Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. checkable combobox with autocomplete

checkable combobox with autocomplete

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 507 Views
  • 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.
  • G Offline
    G Offline
    Gabriel_xyz
    wrote on last edited by
    #1

    Hello everyone!
    I'm trying to implement a combobox with checkable items, so the user can multi-select, and search.

    Here is the code:

    from PyQt5.QtWidgets import QApplication, QComboBox, QCompleter, QLineEdit
    from PyQt5.QtCore import Qt
    
    class CheckableComboBox(QComboBox):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.setEditable(True)
            self.setInsertPolicy(QComboBox.NoInsert)
    
            # Make Completer for Search Box
            self.completer = QCompleter()
            self.completer.setFilterMode(Qt.MatchContains)
            self.completer.setCaseSensitivity(Qt.CaseInsensitive)
    
            # Make Search Box for Combo Box
            self.search_box = QLineEdit()
            self.search_box.setCompleter(self.completer)
            self.search_box.setFocus()
            self.search_box.selectAll()
    
            self.setLineEdit(self.search_box)
            self.completer.setModel(self.model())
    
    
    if __name__ == '__main__':
        app = QApplication([])
        region = ['South', 'North', 'East', 'West']
        combo = CheckableComboBox()
        combo.addItems(region)
        combo.show()
        model = combo.model()
        app.exec()
    
    

    The checkboxes are being displayed, but the auto-compete does not work.

    Any advice would be much appreciated!

    1 Reply Last reply
    0

    • Login

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