PyQt5中怎么使用QComboCheckBox的实现一个下拉式复选框-创新互联
本篇文章为大家展示了PyQt5中怎么使用QComboCheckBox的实现一个下拉式复选框,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
成都创新互联公司专注于企业营销型网站建设、网站重做改版、尼泸西网站定制设计、自适应品牌网站建设、成都h5网站建设、电子商务商城网站建设、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为尼泸西等各大城市提供网站开发制作服务。from PyQt5.QtWidgets import QComboBox,QLineEdit,QListWidget,QCheckBox,QListWidgetItem class ComboCheckBox(QComboBox): def __init__(self,items):#items==[str,str...] super(ComboCheckBox,self).__init__() self.items=items self.qCheckBox=[] self.qLineEdit=QLineEdit() self.qLineEdit.setReadOnly(True) qListWidget=QListWidget() self.row_num=len(self.items) for i in range(self.row_num): self.qCheckBox.append(QCheckBox()) qItem=QListWidgetItem(qListWidget) self.qCheckBox[i].setText(self.items[i]) qListWidget.setItemWidget(qItem,self.qCheckBox[i]) self.qCheckBox[i].stateChanged.connect(self.show) self.setLineEdit(self.qLineEdit) self.setModel(qListWidget.model()) self.setView(qListWidget) def Selectlist(self): Outputlist=[] for i in range(self.row_num): if self.qCheckBox[i].isChecked()==True: Outputlist.append(self.qCheckBox[i].text()) return Outputlist def show(self): show='' self.qLineEdit.setReadOnly(False) self.qLineEdit.clear() for i in self.Selectlist(): show+=i+';' self.qLineEdit.setText(show) self.qLineEdit.setReadOnly(True) from PyQt5.QtWidgets import QComboBox,QLineEdit,QListWidget,QCheckBox,QListWidgetItem class ComboCheckBox(QComboBox): def __init__(self,items):#items==[str,str...] super(ComboCheckBox,self).__init__() 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.show) self.setModel(self.qListWidget.model()) self.setView(self.qListWidget) self.setLineEdit(self.qLineEdit) def addQCheckBox(self,i): self.qCheckBox.append(QCheckBox()) qItem=QListWidgetItem(self.qListWidget) self.qCheckBox[i].setText(self.items[i]) self.qListWidget.setItemWidget(qItem,self.qCheckBox[i]) def Selectlist(self): Outputlist=[] for i in range(1,self.row_num): if self.qCheckBox[i].isChecked()==True: Outputlist.append(self.qCheckBox[i].text()) self.Selectedrow_num=len(Outputlist) return Outputlist def show(self): show='' Outputlist=self.Selectlist() self.qLineEdit.setReadOnly(False) self.qLineEdit.clear() for i in Outputlist: show+=i+';' if self.Selectedrow_num==0: self.qCheckBox[0].setCheckState(0) elif self.Selectedrow_num==self.row_num-1: self.qCheckBox[0].setCheckState(2) else: self.qCheckBox[0].setCheckState(1) self.qLineEdit.setText(show) self.qLineEdit.setReadOnly(True) def All(self,zhuangtai): if zhuangtai==2: for i in range(1,self.row_num): self.qCheckBox[i].setChecked(True) elif zhuangtai==1: if self.Selectedrow_num==0: self.qCheckBox[0].setCheckState(2) elif zhuangtai==0: self.clear() def clear(self): for i in range(self.row_num): self.qCheckBox[i].setChecked(False)
使用方法:
a=ComboCheckBox('子项列表')
Selectlist()获取被选子项列表
All()全选
clear()清空已选项
上述内容就是PyQt5中怎么使用QComboCheckBox的实现一个下拉式复选框,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
当前名称:PyQt5中怎么使用QComboCheckBox的实现一个下拉式复选框-创新互联
转载注明:http://azwzsj.com/article/ccdgoc.html