OpenNumismat / open-numismat

OpenNumismat, is intended primarily for registering a collection of coins. But it is also suitable for other types of collectibles - stamps, postcards, badges and more exotic things.
http://opennumismat.github.io/
GNU General Public License v3.0
95 stars 27 forks source link

[Improvement] Adding the ability for dynamic searching anywhere in the text within the field with dropdowns #171

Open NEKolev opened 7 months ago

NEKolev commented 7 months ago

Currently, the search in the field is rigid from the beginning of the first word, which is not convenient for dropdowns where you don’t know exactly how they are written. For example, Cocos (Keeling) Islands, Heard Island and McDonald Islands, and others. I think this would be very convenient for all fields where the value is selected from a dropdown list.

Something I noticed (it can be seen in the clip) when deleting the country, the flag of the deleted country is not cleared. Version 1.9.6.56-nuitka.exe

https://github.com/OpenNumismat/open-numismat/assets/70388317/50928f85-f9ab-4441-beac-b6d592de794a

NEKolev commented 3 days ago

From what I understand, QComboBox doesn't have dynamic search, but after a brief conversation with Copilot, it suggested the following code for adding custom logic. Of course the code may not be correct, but still.

from PySide6.QtWidgets import QComboBox, QLineEdit, QApplication
from PySide6.QtCore import Qt

class CustomComboBox(QComboBox):
    def __init__(self, parent=None):
        super(CustomComboBox, self).__init__(parent)
        self.setEditable(True)
        self.lineEdit().textChanged.connect(self.filterItems)
        self.all_items = []

    def addItems(self, items):
        super(CustomComboBox, self).addItems(items)
        self.all_items = items

    def filterItems(self):
        search_text = self.lineEdit().text().lower()
        self.clear()
        for item in self.all_items:
            if search_text in item.lower():
                self.addItem(item)

# Using CustomComboBox
app = QApplication([])  # Only needed if there is no existing QApplication
combo_box = CustomComboBox()
combo_box.addItems(['Apple', 'Banana', 'Grapes', 'Orange'])
combo_box.show()
app.exec()