Qcompleter for QAbstractTableModel’s All Columns in Qcombobox/QLineEdit

I have a large dataset with 3 million rows and more than 5 columns, (increasing data day by day)

I want to get the row data by searching/filtering the given text in QLineEdit with matching records highlited
But I could not do the task in QLineEdit that’s why I tried Qcombobox

What I have tried is:

from PyQt5.QtCore import QAbstractTableModel, QModelIndex, Qt
from PyQt5.QtWidgets import (QApplication, QMainWindow, QComboBox, QAbstractItemView,
QCompleter, QTableView, QLabel)
import sys

class CustomCompleter(QCompleter):
def pathFromIndex(self, index):
sibling_index = index.sibling(index.row(), 0)
return super().pathFromIndex(sibling_index)

class TableModel(QAbstractTableModel):
def __init__(self, data):
super().__init__()
self._data = data

    def rowCount(self, parent=QModelIndex()):
        return len(self._data)
    
    def columnCount(self, parent=QModelIndex()):
        return len(self._data[0])
    
    def data(self, index, role=Qt.DisplayRole):
        if role == Qt.DisplayRole:
            return self._data[index.row()][index.column()]
        return None

class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__()
self.label = QLabel(parent = self)
self.label.setGeometry(20,200, 250, 50)
w, h = 600, 480
self.setMinimumSize(w, h)

        # using MySQLdb
        # cur = db()
        # q = 'select id, name_purchase, acchead, name_sale, quantity, edate, quality from dataTableB;'
        # cur.execute(q)
        # data_ = cur.fetchall()
    
        # sample data for minimal reproducable code
        data_ = (
            (101, 'Robert James', 30, 'Robert Clark', '01-02-2024'),
            (102, 'Jack William', 25, 'Hazel Mile', '12-03-2024'),
            (103, 'Ivy Alexander', 30, 'Ellis', '01-04-2024'),
            (101, 'John Mile', 30, 'Lily', '21-04-2024'),
            (103, 'Edward George', 30, 'Arthur', '25-04-2024')
        )
    
        model = TableModel(data_)
    
        combo = QComboBox(self)
        combo.setGeometry(50,50, 250, 40)
        combo.setEditable(True)
        combo.setModel(model)
        combo_view = QTableView(combo, selectionBehavior=QAbstractItemView.SelectRows)
        combo_view.verticalHeader().setVisible(False)
        combo.setView(combo_view)
        combo.currentIndexChanged.connect(self.get_row)
    
        completer_view = QTableView(combo, selectionBehavior=QAbstractItemView.SelectRows)
        completer_view.verticalHeader().hide()
    
        completer = CustomCompleter()
        completer.setCaseSensitivity(False)
        completer.setFilterMode(Qt.MatchContains)
        completer.setModel(model)
        completer.setCompletionColumn(0)
        completer.setPopup(completer_view)
        # completer.setModelSorting(QCompleter.CaseSensitivelySortedModel)
        # completer.setCompletionMode(QCompleter.PopupCompletion)
        # completer.popup().setMinimumWidth(w)
        # completer.popup().setMinimumHeight(h)
        combo.setCompleter(completer)
    
    def get_row(self, n):
        self.label.setText(str(n))

if __name__ == '__main__':
app = QApplication(sys.argv)
main = MainWindow()
main.show()
try:
sys.exit(app.exec_())
except SystemExit:
None

With this code

  1. Qcombobox show the data in tabular format and when i select a row with mouse, it returns the row number but does not fill the data in qcombobox (qcombobox remains empty)
  2. Qcompleter does not show any data (when typing in Qcombobox, no popup appears)

I want the Qcompleter match the text from all columns and highlight the record, and selecting the required row Qcombobox must be filled with the 1st column record e.g 101

If this could be done in QLineEdit (That would be actually helpful) because Qcombobox could be slow when the dataset has more than 3 million rows

The sample result image is as below:

enter image description here

New contributor

Aqsa Farm House is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật