当我在PyQt中单击空QLineEdit(在设置QCompleter之后)小部件时如何显示所有项目?

时间:2015-06-22 08:20:55

标签: python qt pyqt

当我输入某个字符时,QCompleter会弹出包含该字符的项目。当我点击空的QLineEdit时,我想显示所有项目。我有一个解决方案,通过使用QComboBox来解决它,但我希望通过QLineEdit实现它。 谢谢!

#-*-coding:utf-8-*-
#!/usr/bin/env python

from __future__ import division
import sys
from math import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import time

wordlist=['abc','abcv','abdd','asd','bcd']
class Form(QDialog):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.list1=QStringList(wordlist)
        self.line1=QLineEdit()
        self.completer=QCompleter(self.list1)
        self.completer.setCaseSensitivity(Qt.CaseInsensitive)
        self.line1.setCompleter(self.completer)
        layout = QVBoxLayout()
        layout.addWidget((self.line1))
        self.setLayout(layout)
        self.line1.setFocus()
        self.setWindowTitle("QCompleter")


app =QApplication(sys.argv)
form = Form()
form.show()
app.exec_()

0 个答案:

没有答案