|
发表于 2024-4-7 10:02:22
|
显示全部楼层
非常抱歉,下面是根据你的需求进行格式修改后的Python代码示例:
- from PySide6.QtWidgets import QApplication, QMainWindow, QComboBox
- class MainWindow(QMainWindow):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("ComboBox Demo")
- self.combo_box1 = QComboBox(self)
- self.combo_box2 = QComboBox(self)
- self.combo_box3 = QComboBox(self)
- # 假设你已经有了名为data1的列表
- data1 = ["A", "B", "C"]
- self.combo_box1.addItems(data1)
- self.combo_box1.currentIndexChanged.connect(self.handle_combo_box1_change)
- self.setCentralWidget(self.combo_box1)
- def handle_combo_box1_change(self, index):
- selected_item = self.combo_box1.currentText()
- # 这里可以根据选择的项来动态更新combo_box2的数据源
- if selected_item == "A":
- # 假设你已经有了名为data2的列表,是A的子选项
- data2 = ["A11", "A12", "A13", "A14"]
- self.combo_box2.clear()
- self.combo_box2.addItem(".....让用户选择")
- self.combo_box2.addItems(data2)
- # 这里还需要处理其他选项的情况
- def handle_combo_box2_change(self, index):
- selected_item = self.combo_box2.currentText()
- # 这里可以根据选择的项来动态更新combo_box3的数据源
- if selected_item == ".....让用户选择":
- # 根据combo_box2的选择来更新combo_box3的数据源
- # 假设你已经有了名为data3的列表
- data3 = ["A131", "A132", "A133", "A134"]
- self.combo_box3.clear()
- self.combo_box3.addItem(".....让用户选择")
- self.combo_box3.addItems(data3)
- def handle_combo_box3_change(self, index):
- selected_item = self.combo_box3.currentText()
- # 这里可以根据选择的项进行相应的处理
- if __name__ == "__main__":
- app = QApplication()
- window = MainWindow()
- window.show()
- app.exec()
复制代码
希望这次满足了你对Python代码格式的要求。如果还有任何问题,请随时追问。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |
|