pyqt5-QComboBox下拉列表组件

发布时间 2023-10-01 18:49:37作者: 挖洞404

1、介绍

QComboBox,下拉列表组件。

2、项操作

clear(self)
  • 清除项
addItem(self, text: str, userData: Any = None)
addItem(self, icon: QIcon, text: str, userData: Any = None)
  • 添加项
addItems(self, texts: Iterable[str])
  • 添加多个项
insertItem(self, index: int, text: str, userData: Any = None)
insertItem(self, index: int, icon: QIcon, text: str, userData: Any = None)
  • 指定索引处插入项
insertItems(self, index: int, texts: Iterable[str])
  • 指定索引处插入多个项
removeItem(self, index: int)
  • 移除指定索引的项
setMaxVisibleItems(self, maxItems: int)
  • 设置最大可视项的个数

3、项内容

setItemText(self, index: int, text: str) 
  • 设置指定项的文本
itemText(self, index: int) -> str
  • 获取指定项的文本
setItemIcon(self, index: int, icon: QIcon)
  • 设置指定项的图片
itemIcon(self, index: int) -> QIcon 
  • 获取指定项的图片
setItemData(self, index: int, value: Any, role: int = Qt.ItemDataRole.UserRole)
  • 设置指定项的数据
itemData(self, index: int, role: int = Qt.UserRole) -> Any
  • 获取指定项的数据

4、当前项

setCurrentText(self, text: str)
  • 根据文本设置当前项
setCurrentIndex(self, index: int)
  • 根据索引设置当前项
currentText(self) -> str 
  • 获取当前项的文本
currentIndex(self) -> int
  • 获取当前项的索引
currentData(self, role: int = Qt.ItemDataRole.UserRole) -> Any
  • 获取当前项的数据

5、事件

currentIndexChanged(self, index: int) [signal]
currentIndexChanged(self, a0: str) [signal]
  • 当前项索引变化
currentTextChanged(self, a0: str) [signal]
  • 当前项文本变化