import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QEvent
class MyClass(QWidget):
def init(self):
super(MyClass, self).init()
self.initUI()
def initUI(self):
self.setWindowTitle("可编辑并且添加项目的下拉框")
self.setGeometry(300,100,600,150)
myframe = QFrame(self)
myframe.move(50,50)
lbl1=QLabel("你的姓名:",myframe)
lbl1.move(0,3)
self.combo=QComboBox(myframe)
self.combo.setGeometry(60,0,110,20)#move(60,0)
self.combo.setEditable(True)
self.combo.lineEdit().setPlaceholderText("最长六个字符")
self.combo.lineEdit().setMaxLength(6)
self.combo.installEventFilter(self)
self.pushbutton = QPushButton(myframe)
self.pushbutton.move(220, 0)
self.show()
def eventFilter(self, obj, event):
AllItems = [self.combo.itemText(i) for i in range(self.combo.count())]
if obj == self.combo: