Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
87 views
in Technique[技术] by (71.8m points)

python - Limit Number Of Rows in PyQt QCompleter

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.

question from:https://stackoverflow.com/questions/65850537/limit-number-of-rows-in-pyqt-qcompleter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

completer.setMaxVisibleItems(10)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...