网上找不到合适的自定义item内容并能够获得复选内容的combox,所以自己写了个,有需要的直接拿去用即可:
from PyQt5.QtWidgets import QComboBox, QLineEdit, QListWidget, QCheckBox, QListWidgetItem
from PyQt5 import QtWidgets
import sys
class ComboCheckBox(QComboBox):
def __init__(self): # items==[str,str...]
super(ComboCheckBox, self).__init__()
self.items = ''
self.setWindowTitle("批量添加")
def loadItems(self,items):
self.items = items
self.items.insert(0, '全部')
self.row_num = len(self.items)
self.Selectedrow_num = 0
self.qCheckBox = []
self.qLineEdit = QLineEdit()
self.qLineEdit.setReadOnly(True)
self.qListWidget = QListWidget()
self.addQCheckBox(0)
self.qCheckBox[0].stateChanged.connect(self.All)
for i in range(1, self.row_num):
self.addQCheckBox(i)
self.qCheckBox[i].stateChanged.connect(self.showMessage)
self.setModel(self.qListWidget.model())
self.setView(self.qListWidget)
self.setLineEdit(sel