1

How can I limit the number of rows that are displayed in a PyQt QCompleter. For example, if there are 10 matches, how would I limit. This is my code:

from PyQt5.QtWidgets import *
from PyQt5 import QtCore
import sys

class Window(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        layout = QGridLayout()
        self.setLayout(layout)
                                              
        names = ["Apple", "Alps", "August", "Alpha", "Ate", "A""Berry", "Cherry" ]
        completer = QCompleter(names)
                               
        self.lineedit = QLineEdit()
        self.lineedit.setCompleter(completer)
        layout.addWidget(self.lineedit, 0, 0)

app = QApplication(sys.argv)
screen = Window()
screen.show()
sys.exit(app.exec_())

I did try looking this link, but didn't understand it at all. When I tried to set the model, I kept getting errors.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

If you want to set a maximum of visible elements in the QCompleter then you must use the maxVisibleItems property:

completer.setMaxVisibleItems(10)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thanks man! This works. However, it creates a small scrollbar on the side. Do you know how I could disable it? –  Jan 22 '21 at 22:10
  • @Master try with: `completer.popup().setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)` – eyllanesc Jan 22 '21 at 22:12