限制PyQt QCompleter中的行数

2024-06-02 05:56:16 发布

您现在位置:Python中文网/ 问答频道 /正文

如何限制PyQt QCompleter中显示的行数。例如,如果有10个匹配项,我将如何限制。这是我的代码:

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_())

我确实试着看了看,但一点也不懂。当我试图设置模型时,我不断地出错


Tags: fromimportselfappnamesinitsyswindow